1

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 "[email protected]" 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?

1 Answer 1

1

I was able to get this working using the ngx_echo module. The key is the echo_read_request_body directive, which as the name implies explicitly reads the request body.

Removing the line

return 201 $request_body_file;

And replacing it with

echo_read_request_body;
echo $request_body_file;

Did the trick!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .