Java Spring Boot 中 MultipartFile 的最大限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34177873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Max limit of MultipartFile in Spring Boot
提问by Ravindu
Is there a maximum file size that spring boot can handle in a MultipartFile
upload process. I know that I can set the maxFileSize
in the property like multipart.maxFileSize=1Mb
.
spring boot 是否有MultipartFile
上传过程中可以处理的最大文件大小。我知道我可以maxFileSize
在属性中设置multipart.maxFileSize=1Mb
.
So, like that can I allow a huge file to upload, like 50MB. The application runs on the Tomcat server integrated with Spring Boot. Do I need to configure the tomcat server also? Or is the file size unlimited?
所以,这样我可以允许上传一个巨大的文件,比如 50MB。该应用程序运行在与 Spring Boot 集成的 Tomcat 服务器上。我还需要配置tomcat服务器吗?还是文件大小没有限制?
回答by mbaranauskas
Setting multipart.max-file-size=128MB
and multipart.max-request-size=128MB
works for me without additional configuration.
无需额外配置即可设置multipart.max-file-size=128MB
并multipart.max-request-size=128MB
为我工作。
回答by Amol
For unlimited upload file size
无限上传文件大小
It seems setting -1
will make it for infinite file size.
似乎设置-1
将使文件大小无限。
Before Spring Boot 2.0:
在 Spring Boot 2.0 之前:
spring.http.multipart.max-file-size=-1
spring.http.multipart.max-request-size=-1
After Spring Boot 2.0:
在 Spring Boot 2.0 之后:
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1
回答by A. Thom
For those using Spring Boot 2.0 (as of M1 release), the property names have changed to:
对于使用 Spring Boot 2.0(从 M1 版本开始)的用户,属性名称已更改为:
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
Note the prefix is spring.servlet
instead of spring.http
.
请注意前缀是spring.servlet
而不是spring.http
。
回答by Deva
In my application.yml
file
在我的application.yml
文件中
spring:
servlet:
multipart:
max-file-size: 15MB
max-request-size: 15MB
And If you have application.properties
file
如果你有application.properties
文件
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
回答by Patel Romil
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.
Spring Boot 已经将 Tomcat 嵌入其中,因此我们不需要对其进行配置。application-properties 中的 MULTIPART 属性将处理它。
For an external server, the default limit is 50MB
. We can see it by opening webapps/manager/WEB-INF/web.xml
对于外部服务器,默认限制为50MB
。我们打开就可以看到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.
MULTIPART 属性已根据版本更改。
Spring Boot 1.3.x and earlier
Spring Boot 1.3.x 及更早版本
multipart.max-file-size
multipart.max-request-size
After Spring Boot 1.3.x:
在 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 Boot 2.0 之后:
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=-1