SpringBoot's @MultipartConfig maxFileSize not taking effect
With Spring Boot 2.0, you should use this in your application.yml
spring:
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
From documentation:
Spring Boot embraces the Servlet 3
javax.servlet.http.Part
API to support uploading files. By default, Spring Boot configures Spring MVC with a maximum size of 1MB per file and a maximum of 10MB of file data in a single request. You may override these values, the location to which intermediate data is stored (for example, to the/tmp
directory), and the threshold past which data is flushed to disk by using the properties exposed in theMultipartProperties
class. For example, if you want to specify that files be unlimited, set the spring.servlet.multipart.max-file-size property to-1
.
Extracted from Appendix A of documentation
spring.servlet.multipart.max-file-size=1MB # Max file size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
spring.servlet.multipart.max-request-size=10MB # Max request size. Values can use the suffixes "MB" or "KB" to indicate megabytes or kilobytes, respectively.
If you just want to control the multipart properties, you can use multipart.max-file-size
and multipart.max-request-size
properties. For example, you could raise the max size to 100Mb
by adding following piece of configurations in your application.properties
file:
multipart.max-file-size=100MB
multipart.max-request-size=100MB
Values can use the suffixed MB
or KB
to indicate a Megabyte or Kilobyte size.
Under the hood, Spring Boot will create a MultipartConfigElement
based on MultipartProperties
and that MultipartConfigElement
will be used in Servlet registration, as stated in Spring MVC documentation. You can take a look at MultipartAutoConfiguration
and DispatcherServletConfiguration
and Checkout Spring Boot documentation for more information.
With spring-boot 1.5.3 you should use the following code in application.yml
spring:
http:
multipart:
max-file-size: 100MB
max-request-size: 100MB
Make sure to use spaces and not tab in your yaml file.