I\'ve got a fairly simple Spring Boot web application, I have a single HTML page with a form with enctype=\"multipart/form-data\"
. I\'m getting this error:
from documentation: https://spring.io/guides/gs/uploading-files/
Tuning file upload limits
When configuring file uploads, it is often useful to set limits on the size of files. Imagine trying to handle a 5GB file upload! With Spring Boot, we can tune its auto-configured MultipartConfigElement with some property settings.
Add the following properties to your existing
src/main/resources/application.properties
:
spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB
The multipart settings are constrained as follows:
spring.http.multipart.max-file-size is set to 128KB
, meaning total file size cannot exceed 128KB.
spring.http.multipart.max-request-size
is set to 128KB, meaning total request size for a multipart/form-data cannot exceed 128KB.
In application.properties file write this:
# Max file size.
spring.http.multipart.max-file-size=1Mb
# Max request size.
spring.http.multipart.max-request-size=10Mb
Adjust size according to your need.
Note: As of Spring Boot 2, however you can now do
# Max file size.
spring.servlet.multipart.max-file-size=1MB
# Max request size.
spring.servlet.multipart.max-request-size=10MB
Appendix A. Common application properties - Spring