Enforce file upload size on Heroku?

后端 未结 2 811
無奈伤痛
無奈伤痛 2021-01-19 15:14

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

相关标签:
2条回答
  • 2021-01-19 16:04

    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.

    0 讨论(0)
  • 2021-01-19 16:14

    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!

    0 讨论(0)
提交回复
热议问题