Grails3文件上传maxFileSize限制 [英] Grails3 file upload maxFileSize limit
问题描述
我试图在Grails 3中更新文件上传maxFileSize限制,并尝试在 src / main / resources / application.properties
, application.groovy
和 application.yml
,但它仍然抛出异常
<$ p $类
org.apache.tomcat.util.http.fileupload.FileUploadBase $ SizeLimitExceededException
消息
请求被拒绝,因为它的大小(154738)超过了配置最大(128000)
有关Grails 3应用程序中何处以及如何配置的帮助?
解决方案是设置 maxFileSize
和 maxRequestSize
限制在 application.yml
文件中。一定要有这样的东西:
grails:
控制器:
上传:
maxFileSize:2000000
maxRequestSize:2000000
替换 2000000
以及您希望用于文件上传和整个请求的最多字节数。 Grails 3的默认值是128000(〜128KB)。
常见问题解答
1。如何将MB转换为字节?
YOUR_MAX_SIZE_IN_MB * 1024 * 1024 = BYTES
例如转换5 MB字节
5 * 1024 * 1024 = ** 5242880 **字节
2。安全
来自 OWASP
限制文件大小为最大值以防止拒绝服务攻击
因此,这些限制的存在是为了防止DoS攻击和强制执行整体应用程序性能(更大的请求大小==从服务器使用的更多内存)。
$ b
3。什么是 maxFileSize
和 maxRequestSize
?的正确值
这取决于应用程序类型,但将它们保持得太高通常是一个糟糕的主意。如果你真的需要上传大文件,那么你可能应该开发(或使用)一个专门的(和分离的)服务。
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?
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 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.
这篇关于Grails3文件上传maxFileSize限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!