Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

grails - Grails3 file upload maxFileSize limit

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...