I'm trying to configure nginx to support file uploads. I'm using the method described here. My nginx.conf
looks like:
location /upload {
limit_except POST { deny all; }
client_body_temp_path /tmp;
client_body_in_file_only on;
client_body_buffer_size 128K;
client_max_body_size 20G;
return 201 $request_body_file;
}
The idea here is that by switching on client_body_in_file_only
, each request gets saved directly to disk. Also the filename that it was saved to is then returned to the client.
I can upload files with cURL and see that they are getting transferred in their entirety:
$ curl -i -F "data=@test.PNG" http://server/upload > out.txt
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3053k 0 0 100 3053k 0 7874k --:--:-- --:--:-- --:--:-- 7889k
The file is 3 MB, and sure enough 3 MB was transferred. The response is:
$ cat out.txt
HTTP/1.1 100 Continue
HTTP/1.1 201 Created
Server: nginx/1.13.4
Date: Tue, 22 Aug 2017 04:21:48 GMT
Content-Type: text/plain
Content-Length: 0
Connection: keep-alive
Notice that I didn't get back a filename in the response body. Then on the server there's nothing under /tmp/
. Where did the uploaded file go?
Best Answer
I was able to get this working using the
ngx_echo
module. The key is theecho_read_request_body
directive, which as the name implies explicitly reads the request body.Removing the line
And replacing it with
Did the trick!