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.
@Beanannotation. 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.