I currently have a Java Spring Rest API that enables images base64 to be uploaded to my server. Now I would like to know if there is a way I can limit the upload size so that people wont be able to upload 1GB and crash my server.
Asked
Active
Viewed 1.4k times
2 Answers
4
For those using Spring Boot, consider setting the following parameters in your application.properties (or application.yml) file:
multipart.max-file-size=1Mb
multipart.max-request-size=10Mb

David Riccitelli
- 7,491
- 5
- 42
- 56
0
I believe it should be configured on the web server level and not on the code level. For example in tomcat you can configure maxPostSize
param present in server.xml to limit the size of Http POST request.

Juned Ahsan
- 67,789
- 12
- 98
- 136
-
I already tried setting the maxPostSize in tomcat but this doesnt work. I think this is because im sending it with the headers application/json. – Vinchenzo Feb 03 '15 at 18:51
-
1Doesn't matter what is the MIME type. If the size of the POST payload goes beyond the defined limit, the request should be dropped by tomcat. – Juned Ahsan Feb 03 '15 at 23:59