前言:
写项目时突然要跨域上传文件,之前一直是存入到本地文件夹中,但是在尝试了好几个办法后找到了一个办法.
在SpringBoot项目中的application.yml文件中设置如下参数:
spring:
servlet:
multipart:
enabled: true
max-file-size: 30MB
max-request-size: 30MB
file:
upload:
path=http://localhost:8000/upload/:
引入跨服器上传所需要的jar包坐标
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.18.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.18.1</version>
</dependency>
Controller中:
@Value("${file.upload.path}")
private String path;
@PostMapping(path = "/fileupload")
public CommonResult fileupload(@RequestParam("file&#