Arijeet Bhakat
Arijeet Bhakat

Reputation: 109

Unable to set maximum value for "spring.servlet.multipart.max-file-size" in spring boot 2

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.

Upvotes: 1

Views: 3295

Answers (1)

Pijotrek
Pijotrek

Reputation: 3021

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.

Upvotes: 1

Related Questions