Unable to upload file on nginx with Ubuntu 20.04 and nodejs

Posted October 2, 2020 1.2k views

I’m trying to upload files from an app to a nodejs api on digital ocean using nginx as a reverse proxy. I’m using multer to upload form-data, and it works well in my local environment, so I suppose the problem is with nginx.

I have tried various configurations for nginx.conf and the configuration file at /etc/nginx/sites-available/ (setting clientmaxbodysize and clientbodybuffersize to larger values, disabling proxyrequestbuffering, etc), and even tried the whole process with a 60kb file. I’m not getting the 413 error, so setting larger values for some nginx config variables did work, but the file never appears inside the req object (which multer was supposed to extract).

Any tips on how to solve this problem?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Just in case anyone has this same problem, it was specific to multer. I fixed it by by passing multer as middleware to the router. Interestingly one can use multer directly inside the router function in a local environment without any problems.