0

Embedded Tomcat doesn't upload files larger than 10MB

I wrote an endpoint to allow users to upload files into a server with POST. The endpoint kind of work. It uploads files to the server. However, it only uploads files smaller than 10MB. Files that are 10MB or larger run into an issue with MaxUploadSizeExceedException thrown by the embedded Tomcat (below).

I did not set any file upload limit anywhere in the project. I read from somewhere that by the default the embedded Tomcat doesn't have any restriction on the uploading file size.

I tried to edit the file upload size in the application.properties file with the following variables (one at a time):

spring.servlet.multipart.maxFileSize=5000MB
# spring.http.multipart.max-file=5000MB
# multipart.maxFileSize=50mb        # max file size
# multipart.maxRequestSize=50mb     # max reques

Editing the above variables in the application.properties file did not change the 10MB file upload size limitation by the embedded Tomcat. I then created a Bean as follow to specify the upload file size but didn't have much luck:

@Configuration
public class UploadFileSize {
    private long maxFileSize = -1;  // -1 = unlimited size

    public MultipartResolver multipartResolver() {   
        CommonsMultipartResolver multipartResolver = new 
 CommonsMultipartResolver();    
        multipartResolver.setMaxUploadSize(maxFileSize);    
        enter code here

        return multipartResolver;
    }
}

I would have expected the code to be able to upload files of several GB size.

1
  • That is not a bean as it is missing an @Bean annotation. Which property to set actually depends on which Spring Boot version you are using, as things have changed between versions. Please specify which Spring Boot version you are using. Commented Sep 5, 2019 at 15:05

3 Answers 3

0

I use the following configuration to allow unlimited upload size

spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
server.tomcat.max-http-post-size=-1 (!! Maximum size of the HTTP post content)
Sign up to request clarification or add additional context in comments.

Comments

0

As M.Deinum has suggested you need to check your version and set the property accordingly.

Setting the property to -1 will make it for infinite file size. We may change it according to requirements.

application-properties

Spring Boot 1.3.x and earlier

multipart.max-file-size
multipart.max-request-size

After Spring Boot 1.3.x:

spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1

After Spring Boot 2.0:

spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1

Comments

0

Please use the properties below, it works for me.

spring.servlet.multipart.max-file-size=1GB
spring.servlet.multipart.max-request-size=1GB

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.