FileUploadBase$SizeLimitExceeded
2020-09-17 本文已影响0人
莫客991
springboot 文件上传超出大小:MultipartFile file
异常信息如下:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (76559398) exceeds the configured maximum (52428800)] with root cause
projectVersion _
stackTrace {
"method": "<init>",
"class": "org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl",
"file": "FileUploadBase.java",
"line": 811
},
{
"method": "getItemIterator",
"class": "org.apache.tomcat.util.http.fileupload.FileUploadBase",
"file": "FileUploadBase.java",
"line": 256
},
{
"method": "parseRequest",
"class": "org.apache.tomcat.util.http.fileupload.FileUploadBase",
"file": "FileUploadBase.java",
"line": 280
},
{
"method": "parseParts",
"class": "org.apache.catalina.connector.Request",
"file": "Request.java",
"line": 2801
},
{
"method": "parseParameters",
"class": "org.apache.catalina.connector.Request",
"file": "Request.java",
"line": 3177
},
{
"method": "getParameter",
"class": "org.apache.catalina.connector.Request",
"file": "Request.java",
"line": 1110
},
解决方案:
使用这种发现不生效:
uploadFile 修改上传文件的大小限制
spring.http.multipart.max-file-size=100MB
spring.servlet.multipart.max-file-size=100MB
spring.servlet.multipart.max-request-size=100MB
生效方案如下:完美解决
/**
- 修改上传文件的大小限制
- @author heng
*/
@Configuration
public class MultipartConfig {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxRequestSize("200Mb");
factory.setMaxFileSize("200Mb");
return factory.createMultipartConfig();
}
}