我正在尝试设置Nginx来处理文件上传,并在完成后将文件信息传递到后端服务器.我在https://coderwall.com/p/swgfvw发现了一个帖子,显示了如何执行此操作,我能够看到一个文件被上传到/ tmp目录.但是,我还想将文件名和类型(Content-Disposition和Content-Type)传递给后端服务器.
POST /upload HTTP/1.1
User-Agent: curl/7.32.0
Host: MyHostName
Accept: */*
Content-Length: 4431
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------6060af4f937c14c9
--------------------------6060af4f937c14c9
Content-Disposition: form-data; name="filedata"; filename="sessions.txt"
Content-Type: text/plain
其次是数据.
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 100M;
proxy_redirect off;
proxy_set_header X-FILE $request_body_file;
proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection "";
proxy_pass_request_headers on;
proxy_set_body off;
proxy_http_version 1.1;
proxy_pass http://my_backend;
}
有了这个,我能够在我的后端传递并接收以下内容,
'content-type': 'multipart/form-data; boundary=------------------------6060af4f937c14c9'
'x-file': '/tmp/0000000001'
但我真的很想知道如何获得
Content-Disposition: form-data; name="filedata"; filename="sessions.txt"
Content-Type: text/plain
到我的后端.对此有任何帮助非常感谢.
最佳答案
如果标题被忽略,请尝试
原文链接:https://www.f2er.com/nginx/434423.htmlproxy_pass_header Content-Disposition;
或直接通过
proxy_set_header Content-Disposition $http_content_disposition;