Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring MVC文件上载到项目目录_Spring_Spring Mvc_File Upload - Fatal编程技术网

Spring MVC文件上载到项目目录

Spring MVC文件上载到项目目录,spring,spring-mvc,file-upload,Spring,Spring Mvc,File Upload,如何将文件上传到实际的项目文件夹而不是tmp0文件夹?我会尝试一下社区项目。这个项目使得处理文件上传/下载/流式传输以及将内容与Spring数据实体相关联变得非常容易 添加它会像这样: xml(假设maven.Spring引导启动器也可用) FileStore.java @StoreRestResource(path=“files”) 公共接口文件存储扩展存储{ } 就这样。文件存储本质上是一个通用的Spring ResourceLoader。spring-content-fs依赖项将导致sp

如何将文件上传到实际的项目文件夹而不是tmp0文件夹?

我会尝试一下社区项目。这个项目使得处理文件上传/下载/流式传输以及将内容与Spring数据实体相关联变得非常容易

添加它会像这样:

xml(假设maven.Spring引导启动器也可用)

FileStore.java

@StoreRestResource(path=“files”)
公共接口文件存储扩展存储{
}
就这样。文件存储本质上是一个通用的Spring ResourceLoader。
spring-content-fs
依赖项将导致spring-content注入基于文件系统的实现。如果
@Controller
将HTTP请求转发到
文件存储
服务的方法上,则
spring内容rest
依赖项将导致spring内容也注入一个实现

因此,您现在将在
/files
上拥有一个功能齐全的(POST、PUT、GET、DELETE)基于REST的文件服务,它将使用您的
文件存储
在jboss服务器上的
/path/to/upload/files
中检索(和存储)文件

因此:

curl-F'data=@path/to/local/image.jpg'/files/image.jpg

将上载
image.jpg
并将其存储在服务器上的
/path/to/upload/files

以及:

curl/files/image.jpg

我会再次找回它

@Controller {
   String path = request.getSession().getServletContext().getRealPath();
   System.out.println(path);
   D:\folder1\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\project-name\
   file.transferTo(new File(path+file.getOriginalFilename()));  
}
    <!-- Java API -->
    <!-- just change this depdendency if you want to store somewhere else -->
    <dependency>
        <groupId>com.github.paulcwarren</groupId>
        <artifactId>spring-content-fs</artifactId>
        <version>1.1.0.M3</version>
    </dependency>
    <!-- REST API -->
    <dependency>
        <groupId>com.github.paulcwarren</groupId>
        <artifactId>spring-content-rest</artifactId>
        <version>1.1.0.M3</version>
    </dependency>
@Configuration
@EnableFilesystemStores
@Import(RestConfiguration.class)
public class StoreConfig {

    @Bean
    FileSystemResourceLoader fileSystemResourceLoader() throws IOException {
        return new FileSystemResourceLoader(new File("/path/to/uploaded/files").getAbsolutePath());
    }

}
  @StoreRestResource(path="files")
  public interface FileStore extends Store<String> {
  }