Grails 3 and 4
The solution is to set maxFileSize
and maxRequestSize
limits inside your application.yml
file. 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 and Grails 4 default is 128000 (~128KB).
FAQ
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 quote from OWASP
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…