Search code examples
javaspring-bootupload

"the request was rejected because its size " Spring, tomcat


I'm trying to make a simple upload app with springboot and it works fine until i try to upload 10Mb+ files, i receive this message on my screen:

There was an unexpected error (type=Internal Server Error, status=500).
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 (14326061) exceeds the configured maximum (10485760)

I've done some research, and nothing have worked until now. I'll leave here below the things i've tried so far.

put this code(In various ways) in my "application.yml"

multipart: 
 maxFileSize: 51200KB
 maxRequestFile: 51200KB  

I've also tried this in my principal class:

    @Bean
public TomcatEmbeddedServletContainerFactory containerFactory() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
     factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
         ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
     });
     return factory;
}

And some strange thing. If i enter in my tomcat web.xml, the multipart-config is:

<multipart-config>
      <!-- 50MB max -->
      <max-file-size>52428800</max-file-size>
      <max-request-size>52428800</max-request-size>
      <file-size-threshold>0</file-size-threshold>
    </multipart-config>

So where the hell this "...configured maximum (10485760)" is coming from ? (Sidenote: I'm using netbeans 8.1 and springboot 1.5).

Thx guys.(And sorry for the english s2)

Since asked, this is my application.yml

 server:
      port: 9999
      context-path: /client
    logging:
      level:
        org.springframework.security: DEBUG
    endpoints:
      trace:
        sensitive: false

    spring:
        thymeleaf:
            cache: false
        multipart: 
          maxFileSize: 51200KB
          maxRequestFile: 51200KB  

    #################################################################################

    security:
      basic:
        enabled: false
      oauth2:
        client:
          client-id: acme2
          client-secret: acmesecret2
          access-token-uri: http://localhost:8080/oauth/token
          user-authorization-uri: http://localhost:8080/oauth/authorize
        resource:
          user-info-uri: http://localhost:8080/me
    #    

Solution

  • spring:
      http:
        multipart:
          enabled: true
          max-file-size: 50MB
          max-request-size: 50MB
    

    or

    spring.http.multipart.max-file-size=50MB
    spring.http.multipart.max-request-size=50MB
    

    Reference here

    Hope it will works