在Heroku上强制文件上传大小? [英] Enforce file upload size on Heroku?

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

问题描述

Heroku上有一个Rails应用程序。如果可能,我想限制文件上传的大小。该文件被作为一个StringIO对象来处理,因此文件内容将在内存中处理(不需要将中间文件写入文件系统)。

通常,我会限制Web服务器上的上传大小。但是用Heroku,有什么选择呢?我意识到我可以使用Flash上​​传器,但是我希望避免在客户端上使用Flash,如果可能的话。

解决方案

Heroku将请求实体限制在一个很小的尺寸(30MB),并将所有的请求/响应周期限制在30秒。



默认情况下,Rails将文件上传到磁盘,然后将它们转换为Tempfile实例,然后将它们交给您的应用程序。


Got a Rails app on Heroku. I want to limit the size of a file upload if possible. The file is processed as a StringIO object, so the file contents will be processed in memory (have no need to write an intermediate file to a filesystem).

Ordinarily, I would limit upload size on the web server. But with Heroku, what options are there? I realize I could go with a Flash uploader, but I'm hoping to avoid requiring Flash on the client, if at all possible.

解决方案

Heroku limits the request entity to some small size (30MB), and also limits all request/response cycles to 30s. Both are hard rules and must be lived with.

Rails by default spools file uploads to disk and translates them to Tempfile instances before handing them off to your application.

这篇关于在Heroku上强制文件上传大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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