Spring 引导中 MultipartFile 的最大限制

MultipartFile上传过程中,弹簧启动是否可以处理最大文件大小。我知道我可以在属性中设置 maxFileSize,比如 multipart.maxFileSize=1Mb

所以,像这样,我可以允许一个巨大的文件上传,像50 MB。应用程序运行在与 SpringBoot 集成的 Tomcat 服务器上。我是否还需要配置 tomcat 服务器?还是文件大小为 没有限制

119824 次浏览

Setting multipart.max-file-size=128MB and multipart.max-request-size=128MB works for me without additional configuration.

For unlimited upload file size

It seems setting -1 will make it for infinite file size.

Before Spring Boot 2.0:

spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1

After Spring Boot 2.0:

spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1

For those using Spring Boot 2.0 (as of M1 release), the property names have changed to:

spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB

Note the prefix is spring.servlet instead of spring.http.

In my application.yml file

spring:
servlet:
multipart:
max-file-size: 15MB
max-request-size: 15MB

And If you have application.properties file

spring.servlet.multipart.max-file-size = 15MB
spring.servlet.multipart.max-request-size = 15MB

Even You can set file size to infinite

spring.servlet.multipart.max-file-size =-1
spring.servlet.multipart.max-request-size =-1

Spring Boot have embbeed Tomcat with it so we don't need to configure it. MULTIPART properties in application-properties will take care of it.

For an external server, the default limit is 50MB. We can see it by opening webapps/manager/WEB-INF/web.xml

<multipart-config>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>

MULTIPART properties have been changed according to versions.

Spring Boot 1.3.x and earlier

multipart.max-file-size
multipart.max-request-size

After Spring Boot 1.3.x:

spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1

After Spring Boot 2.0:

spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1

I am still looking for the answer, What is maximum size we can upload with multiPartFile in springboot application but i have used 450mb successfully and it took approx 10min to do that. Below is the only configuration i did in application.properties file to make it work :

spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MB

This gonna work

spring:
servlet:
multipart:
enabled: true
max-file-size: 4GB
max-request-size: 4GB