目录
官方文档解决办法——可以传比较大的zip压缩图片啥的。。。。
5、如果上传过大文件出现问题如下——the request was rejected because its size (26246240) exceeds the configured
-
1、上传文件微服务
- 1、pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
- 2、删除文件的controller.java
@RestController
public class FileUploadController {
/**
* 上传文件
* 测试方法:
* 测试接口:http://localhost:8050/upload
* 使用PostMan测试
*
* @param file 待上传文件
* @return
*/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public
@ResponseBody
String handleFileUpload(@RequestParam(value = "file", required = true) MultipartFile file) {
File fileToSave = null;
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
fileToSave = new File(file.getOriginalFilename());
//fileToSave = new File("D:\\测绘管理系统\\文件系统\\文件存储" + file.getOriginalFilename()); 自定义存储路径
FileCopyUtils.copy(bytes, fileToSave);
} catch (IOException e) {
e.printStackTrace();
return "上传失败," + e.getMessage();
}
return "上传成功" + fileToSave.getAbsolutePath();
} else {
return "上传失败,因为文件是空的.";
}
}
}
- 3、application.yml
server:
port: 8050
eureka:
client:
service-url:
defa