4mb image file upload gives HTTP 413 error when uploading to production server 4mb image file upload gives HTTP 413 error when uploading to production server express express

4mb image file upload gives HTTP 413 error when uploading to production server


When using a webserver like Nginx before Node, all requests go through Nginx and are validated by nginx before even reaching Node.js.

Nginx has a configuration file by default located in /etc/nginx/nginx.conf. This file has a lot of default properties for all requests and one of these is client_max_body_size. The default value for that property is 1m, like your 1MB file.

That is also the reason your .htaccess file didn't do anything (Node.js itself never does anything with .htaccess, unless you want it to)

You can manually change it to a different number and that'll be the new max body size for nginx (after reload nginx), but if you want "full" control and have the application check the body size, you can also set it to 0, to disable checking the client request body size.
Setting size to 0 disables checking of client request body size.

Note that changing that property, also changes the max upload size for the PHP requests.