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?
Also in Spring boot 1.4, you can add following lines to your application.properties to set the file size limit:
spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB
for spring boot 2.x and above its
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
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:
MaxFileSize: The maximum size allowed for uploaded files, in bytes. If the size of any uploaded file is greater than this size, the web container will throw an exception (IllegalStateException). The default size is unlimited.
MaxRequestSize: The maximum size allowed for a multipart/form-data request, in bytes. The web container will throw an exception if the overall size of all uploaded files exceeds this threshold. The default size is unlimited.
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.