美文网首页
FileUploadBase$SizeLimitExceeded

FileUploadBase$SizeLimitExceeded

作者: 莫客991 | 来源:发表于2020-09-17 14:40 被阅读0次

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();
    }
    }

相关文章

网友评论

      本文标题:FileUploadBase$SizeLimitExceeded

      本文链接:https://www.haomeiwen.com/subject/tfvlyktx.html