Grails3 file upload maxFileSize limit

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).



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 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.

Leave a Comment