admin管理员组文章数量:1550527
1、场景
上传文件,文件大小1.7M,请求接口报错
接口:
@PostMapping("/import")
@ResponseBody
public FormatResponse imports(@RequestParam("file") MultipartFile file) {
/**省略业务代码**/
}
2、定位原因
查看日志:
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded;
nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.
查看源码知:默认maxFileSize为1MB
@ConfigurationProperties(prefix = "spring.servlet.multipart", ignoreUnknownFields = false)
public class MultipartProperties {
/**
* Whether to enable support of multipart uploads.
*/
private boolean enabled = true;
/**
* Intermediate location of uploaded files.
*/
private String location;
/**
* Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or
* kilobytes, respectively.
*/
private String maxFileSize = "1MB";
/**
* Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or
* kilobytes, respectively.
*/
private String maxRequestSize = "10MB";
/**
* Threshold after which files are written to disk. Values can use the suffixes "MB"
* or "KB" to indicate megabytes or kilobytes, respectively.
*/
private String fileSizeThreshold = "0";
/**
* Whether to resolve the multipart request lazily at the time of file or parameter
* access.
*/
private boolean resolveLazily = false;
}
3、解决方案:
配置maxFileSize参数
spring:
servlet:
multipart:
maxFileSize: 2MB
配置完成本地成功上传1.7M文件(localhost)
4、环境运行
部署测试环境上传失败
Response Headers如下:Request Entity Too Large
HTTP/1.1 413 Request Entity Too Large
date: Mon, 01 Mar 2021 09:20:53 GMT
content-type: text/html
content-length: 578
联系运营修改域名配置
本文标签: MaximumMaxUploadSizeExceededExceptionUploadexceededsize
版权声明:本文标题:MaxUploadSizeExceededException: Maximum upload size exceeded 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1727248763a1104967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论