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
},
解決方案:
使用這種發(fā)現(xiàn)不生效:
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();
}
}