Enforce file upload size on Heroku?

后端 未结 2 812
無奈伤痛
無奈伤痛 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: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!

提交回复
热议问题