Grails3 文件上传 maxFileSize 限制 [英] Grails3 file upload maxFileSize limit

查看:21
本文介绍了Grails3 文件上传 maxFileSize 限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新 Grails 3 中的文件上传 maxFileSize 限制,并尝试了 src/main/resources/application.propertiesapplication.groovyapplication.yml,但它仍然抛出异常

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)

关于在 Grails 3 应用程序中配置的位置和内容有什么帮助吗?

Any help on where and what to configure in a Grails 3 application?

推荐答案

Grails 3 和 4

解决方案是在 application.yml 文件中设置 maxFileSizemaxRequestSize 限制.一定要有这样的东西:

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

2000000 替换为文件上传和整个请求所需的最大字节数.Grails 3Grails4 默认是 128000 (~128KB).

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

1.如何从 MB 转换为字节?

YOUR_MAX_SIZE_IN_MB * 1024 * 1024 = BYTES

例如以字节为单位转换 5 MB

5 * 1024 * 1024 = **5242880** bytes

2.安全

引用自 OWASP

将文件大小限制为最大值以防止拒绝服务攻击

Limit the file size to a maximum value in order to prevent denial of service attacks

因此,存在这些限制是为了防止 DoS 攻击并增强整体应用程序性能(更大的请求大小 == 使用服务器的更多内存).

So these limits exist to prevent DoS attacks and to enforce overall application performance (bigger request size == more memory used from the server).

3.maxFileSizemaxRequestSize 的正确值是多少?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆