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 mem
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.
You could run NGINX
in front of your app server to enforce this constraint.
This is fairly simple with heroku
, you will need a nginx.conf
and this buildpack.
# nginx.conf
http {
#...
client_max_body_size 100m;
#...
}
Note: But be aware that on heroku, NGINX
run inside your dynos (ie. local to each instance).
https://blog.codeship.com/how-to-deploy-nginx-on-heroku
Hope that's help!