nginx is eating my client request - multipart/form-data file upload

Jason H jhihn at
Sun Dec 14 15:43:51 UTC 2014

I am new to nginx, but am familar with low-level HTTP and apache. When I try to do a multipart/form file upload, nginx writes some of the client request body to disk, but never finishes and it never passes it to the down/upstream script.

My specific setup is I have nginx with /dyn redirected to localhost:1337, where a node.js instance is listening. It works... except for the file upload handler. Also in the config is a /debug which is redirected to localhost:1338, which goes to a simple socket dump server for viewing the post.

I changed the error log handling to 'info'. It reports storing the client body to a file and when I examine it, it is almost as I expected:

Content-Type: image/jpeg
Content-Disposition: form-data; name="file"; filename="dccde7b5-25aa-4bb2-96a6-81e9358f2252.jpg"

<binary data, supposed to be ~89k>

The problem with this file is too short, only 81,920 bytes (only 80k, exactly) when the file is 88,963 bytes, it should be 88,963 + the header above.... But that is literally only half of it. There are 2 files (about the same size, 90k) that are coming in, so I would expect that file to be about ~180k. What nginx is then doing is reassigning the request's http-level Content-length to 357ish bytes then passes that header on to the script, that's it and of course my script complains that it never finds --boundary_.oOo._MjM5NzEwOTkxMzU2MjA0NjM5MTQxNDA3MjYwOA== 

When I do the same request to my debug service without nginx in the middle, it correctly sends the data, and the http Content-length is an appropriate 186943 bytes (both files are around 90k, so this makes sense)

My nginx config is default aside from what I've mentioned here. and the my experimenting to solve this issue:
client_max_body_size 2m;
client_body_in_file_only on;
client_body_in_single_buffer on;
client_body_buffer_size 1m;

I am not trying to have nginx strip the file attachments, I want them forwarded to the application.

Any help would be appreciated. I'm perplexed as to why the file is limited to exactly 80k. Nothing is 80k anywhere in nginx. 

More information about the nginx mailing list