99

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.

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?

Romil Patel
  • 12,879
  • 7
  • 47
  • 76
Ravindu
  • 2,408
  • 8
  • 30
  • 46
  • as far as I know, it's better to set maxFileSize and maxRequestSize... good question anyway! – Ivan Aracki Dec 09 '15 at 13:02
  • i want to what is the maxfile size it can handle. – Ravindu Dec 10 '15 at 03:01
  • 2
    Unlimited is never a good thing for stuff like this. Better to set it to a large number - bigger than you would ever expect. Someone uploads a file larger than that, and it may very well be an attack, and you'll be grateful for that `IllegalStateException` that saved your site. – Tony the Tech Mar 28 '19 at 20:43

8 Answers8

134

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.

Grant Foster
  • 722
  • 2
  • 11
  • 21
A. Thom
  • 1,568
  • 1
  • 11
  • 8
  • 3
    Tried looking for difference between these two but no luck. Can you please share some reference? – Pratik Ambani May 14 '21 at 11:48
  • 3
    If your request has multiple files then max-request-size will be limit of size combining all files. – Alfaz Jikani Aug 02 '21 at 03:03
  • make sure you dont leave space such as 10 MB. correct: it should be 10MB – kuhajeyan Dec 17 '21 at 13:14
  • Defaults can be found in [the official docs](https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#appendix.application-properties.web) (search for "multipart") – Cat-Lord Oct 20 '22 at 11:41
78

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
Grant Foster
  • 722
  • 2
  • 11
  • 21
Amol
  • 835
  • 6
  • 5
  • 3
    For more specific: `spring.http.multipart.max-file-size=128KB` `spring.http.multipart.max-request-size=128KB` – jimmbraddock Dec 15 '16 at 10:33
  • 4
    I tested this solution and it worked for me. 400GB file uploaded! I didn't have to configure nothing else because i'm using jetty. spring.http.multipart.max-file-size=-1 spring.http.multipart.max-request-size=-1 as sugested by @jimmbraddock – Marcos Paulo SUS Jan 27 '17 at 18:31
  • As in test, we never know what size of the file a user will input, this answer is exactly what I'm looking for! – Lime莉茉 Oct 11 '21 at 20:35
31

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
Deva
  • 1,851
  • 21
  • 22
14

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 
Romil Patel
  • 12,879
  • 7
  • 47
  • 76
2

This gonna work

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

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

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

Grant Foster
  • 722
  • 2
  • 11
  • 21
mbaranauskas
  • 435
  • 1
  • 4
  • 8
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
0

If you are using Spring 3+ and tomcat 10+ server.tomcat.max-http-form-post-size=4000MB is the properties you are looking for. All the others are not working for setting the max file size

nandha
  • 51
  • 6