1

What is the maximum value which can be set for "spring.servlet.multipart.max-file-size" for multipart uploads in spring boot 2?

Can we set it to unlimited?, I have read on the other blogs that setting it to -1 will allow unlimited but it didn't work for me.

I tried putting this in application.properties but was of no help

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

UPDATE:

1) When I post a file using Postman which is less than 10MB my file gets uploaded and in another scenario I get

{
    "timestamp": 1551270385443,
    "message": "java.io.IOException: UT000020: Connection terminated as request was larger than 10485760",
    "path": "v1/order/upload/"
}

which is equivalent to the response I get if I don't configure the max-file-size and max-request-size property in application.properties

The tutorial which I am using: https://www.callicoder.com/spring-boot-file-upload-download-rest-api-example/

2)

spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=-1
spring.servlet.multipart.max-request-size=1024MB

the above configuration allows me to upload file greater than 10MB.

  • Possible duplicate of [Max Limit of MultipartFile in spring boot](https://stackoverflow.com/questions/34177873/max-limit-of-multipartfile-in-spring-boot) – juanlumn Feb 27 '19 at 12:11

1 Answers1

1

According to documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

and an uploading tutorial here: https://spring.io/guides/gs/uploading-files/

I am pretty sure your properties are correct.

You haven't provided any code or other properties so below is my suspision only:

spring.servlet.multipart.max-file-size=-1 is one thing, but together with it, you should also set spring.servlet.multipart.max-request-size accordingly because it might be the case that the whole request is rejected.

Pijotrek
  • 2,821
  • 1
  • 18
  • 32
  • I tried configuring the max-request-size also but still getting the exception, I have updated my question, please have a look. – Arijeet Bhakat Feb 27 '19 at 14:35
  • Then it sounds mysterious :) are you sure your `application.properties` are in the correct place and being picked up? – Pijotrek Feb 28 '19 at 06:30
  • lol, yes it is in the correct place and the reason behind that is I have been able to change those configurations to different sizes and upload them successfully without any issues, it's just the -1 config which I am having issues with. – Arijeet Bhakat Feb 28 '19 at 08:47
  • and what happens if you explicitly set the value from -1 to lets say 100MB and then send, i.e 15MB request? Can you try it? – Pijotrek Feb 28 '19 at 08:58
  • I just tested it on my test-project. I set up properties like you and successfully uploaded 20MB+ file... My spring-boot version is 2.1.1 - what is yours? – Pijotrek Feb 28 '19 at 09:04
  • yes, I tried uploading a 13.7MB file with 100MB as setting and it works fine, I am able to upload the file successfully. – Arijeet Bhakat Feb 28 '19 at 09:07
  • mine is 2.0.0, what did you set for "spring.servlet.multipart.max-request-size" ? , and I was able to set the "spring.servlet.multipart.max-file-size=-1" and "spring.servlet.multipart.max-request-size=10240MB" and I was able to upload a 80 MB file but i am still not able to upload file larger than default size with max-request-size set to -1. – Arijeet Bhakat Feb 28 '19 at 09:12
  • 1
    I just copied properties from your question so those were `-1`s. – Pijotrek Feb 28 '19 at 09:17
  • Further update: also worked for `2.0.0.RELEASE`. Please share your pom.xml maybe? – Pijotrek Feb 28 '19 at 09:26