Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails file upload size limit

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.

like image 798
Mato Avatar asked Feb 04 '10 14:02

Mato


2 Answers

You may cap the upload size via Apache using the LimitRequestBody directive:

<Directory "/var/www">
    LimitRequestBody 1024
</Directory>

http://httpd.apache.org/docs/1.3/mod/core.html#limitrequestbody

like image 63
meagar Avatar answered Sep 19 '22 11:09

meagar


Or if you're using nginx with passenger, add in the server block:

server {
  client_max_body_size 100M;
}

http://wiki.nginx.org/NginxHttpCoreModule#client_max_body_size

like image 34
Jack Chu Avatar answered Sep 21 '22 11:09

Jack Chu