Rails 文件上传大小限制
有谁知道在使用 Passenger/mod_rails 运行 Rails 应用程序时限制文件上传大小的好解决方案。应立即拒绝该请求,以便文件不会传输到服务器。
到目前为止我找到的解决方案都描述了如何修补 Mongrel 以实现限制,但我必须在这个应用程序中使用乘客。
Does anyone know a good solution to limit the file upload size when running a Rails application with Passenger/mod_rails. The request should immediately be declined, so that the file doesn't get transferred to the server.
The solutions I've found so far all describe how to patch Mongrel to implement a limitation, but I have to use passenger with this application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
或者,如果您将 nginx 与乘客一起使用,请添加服务器块:
http://wiki.nginx.org /NginxHttpCoreModule#client_max_body_size
Or if you're using nginx with passenger, add in the server block:
http://wiki.nginx.org/NginxHttpCoreModule#client_max_body_size
您可以使用 LimitRequestBody 指令通过 Apache 限制上传大小:
http:// httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody
You may cap the upload size via Apache using the LimitRequestBody directive:
http://httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody
您可以使用以下 JavaScript 来通知用户所选文件超出最大限制。但服务器端验证仍然很重要。
MAX_LIMIT_FOR_FILE 以字节为单位,因此如果您想设置最大限制为 1Mb,则 MAX_LIMIT_FOR_FILE 的值应为 1048576
You can use following javascript to notify user that the selected file exceeds maximum limit. But still its essential to have server side validation.
MAX_LIMIT_FOR_FILE is in byte so if you want set max limit of 1Mb then value of MAX_LIMIT_FOR_FILE should be 1048576