yml:配置
spring:
servlet:
multipart:
# 默认支持文件上传
enabled: true
# 最大支持文件大小
max-file-size: 180MB
# 最大支持请求大小
max-request-size: 200MB
工具类
public class IOUtils {
public static ResultObject upload(MultipartFile source, String targetPath) {
if (source == null || source.isEmpty()) {
return ResultHand.error("文件为空");
}
if (source.getSize() <= 0) {
return ResultHand.error("文件大小为空,上传失败");
}
File targetFile = new File(targetPath, fileName);
try {
source.transferTo(targetFile);//io封装的上传工具
} catch (IOException e) {
e.printStackTrace();
}
return ResultHand.success(fileName);
}
}



