Nginx: check content-length before file upload takes place

Posted by robw on Stack Overflow See other posts from Stack Overflow or by robw
Published on 2011-06-18T14:36:10Z Indexed on 2011/06/28 8:22 UTC
Read the original article Hit count: 249

Filed under:
|
|

I'm trying to prevent users from uploading (accidentally or maliciously) very large files to my website.

I have nginx max_client_body_size set to 4M, but if a file larger than this is uploaded, then it uploads the entire file before returning 413 (entity too large).

I want to make nginx check the Content-Length header, so that it rejects the request before it's uploaded.

Alternatively, a Rails solution would also be acceptable.

Any help appreciated.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about upload