I am trying to update the file upload maxFileSize limit in Grails 3 and tried the configuration in src/main/resources/application.properties
, application.groovy
and application.yml
, but it's still throwing the exception
Class
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException
Message
the request was rejected because its size (154738) exceeds the configured maximum (128000)
Any help on where and what to configure in a Grails 3 application?
Grails 3, Grails 4 and Grails 5
The solution is to set maxFileSize
and maxRequestSize
limits inside your application.yml
file (usually placed inside grails-app/conf/
). Be sure to have something like this:
grails:
controllers:
upload:
maxFileSize: 2000000
maxRequestSize: 2000000
Replace 2000000
with the number of max bytes you want for a file upload and for the entire request. Grails 3, Grails 4 and Grails 5 default is 128000 (~128KB).
1. How to convert from MB to bytes?
YOUR_MAX_SIZE_IN_MB * 1024 * 1024 = BYTES
E.g. Convert 5 MB in bytes
5 * 1024 * 1024 = **5242880** bytes
2. Security
As OWASP says
Limit the file size to a maximum value in order to prevent denial of service attacks
So these limits exist to prevent DoS attacks and to enforce overall application performance (bigger request size == more memory used from the server).
3. What is the right value for maxFileSize
and maxRequestSize
?
It depends on the application type, but it's generally a bad idea to keep them too high. If you really need to upload big files, probably you should develop (or use) a dedicated (and separated) service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With