I'm developing application based on Spring Boot and AngularJS using JHipster. My question is how to set max size of uploading files?
If I'm trying to upload to big file I'm getting this information in console:
DEBUG 11768 --- [io-8080-exec-10] c.a.app.aop.logging.LoggingAspect:
Enter: com.anuglarspring.app.web.rest.errors.ExceptionTranslator.processRuntimeException() with argument[s] =
[org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException:
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum permitted size of 1048576 bytes.]
And server response with status 500.
How to set that?
To avoid this exception you can take help of VM arguments just as I used in Spring 1.5.8.RELEASE:
In Spring Boot 2 the
spring.http.multipart
changed tospring.servlet.multipart
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0.0-M1-Release-Notes#multipart-configuration
I'm using
spring-boot-1.3.5.RELEASE
and I had the same issue. None of above solutions are not worked for me. But finally adding following property toapplication.properties
was fixed the problem.You need to set the
multipart.maxFileSize
andmultipart.maxRequestSize
parameters to higher values than the default. This can be done in your spring boot configuration yml files. For example, adding the following toapplication.yml
will allow users to upload 10Mb files:If the user needs to be able to upload multiple files in a single request and they may total more than 10Mb, then you will need to configure
multipart.maxRequestSize
to a higher value:Source: https://spring.io/guides/gs/uploading-files/
Also in Spring boot 1.4, you can add following lines to your application.properties to set the file size limit:
Worked for me. Source: https://spring.io/guides/gs/uploading-files/
UPDATE:
Somebody asked the differences between the two properties.
Below are the formal definitions:
To explain each:
MaxFileSize: The limit for a single file to upload. This is applied for the single file limit only.
MaxRequestSize: The limit for the total size of all files in a single upload request. This checks the total limit. Let's say you have two files a.txt and b.txt for a single upload request. a.txt is 5kb and b.txt is 7kb so the
MaxRequestSize
should be above 12kb.None of the configuration above worked for me with a Spring application.
Implementing this code in the main application class (the one annotated with @SpringBootApplication) did the trick.
You can change the accepted size in the statement: