nginx file upload with client_body_in_file_only

夙愿已清 提交于 2021-02-19 02:39:18

问题


Good evening, I need to upload static content to nginx server 1.9 (so upload module didn't work with this version). I've read the article "Nginx direct file upload without passing them through backend" and followed instructions step by step. Everything works for me, except file names at the nginx data directory. File names look like '0000000001', '0061565403' and so on. What should I do to save files with their correct names? Here is my nginx location config:

location /upload {
limit_except POST              { deny all; }
client_body_temp_path          /data/;
client_body_in_file_only       on;
client_body_buffer_size        128K;
client_max_body_size           50M;
proxy_pass_request_headers     on;
proxy_set_header content-type "text/html";
proxy_set_body                 $request_body_file;
proxy_pass                     http://localhost:8080/
proxy_redirect                 off;}

回答1:


You can use HTTP header in the client to pass the correct name (whatever that is), e.g.:

Correct-Filename: my-correct-filename

And since you're using proxy_pass_request_headers on, the header is visible in the back end where you can use it when saving the file. However when using headers the filename is limited to using ASCII characters, see this answer.




回答2:


The only way I have been able to do this is to send the original filename as a parameter (I use JS to copy the filename to a hidden field), and then, on the server, if I am storing the temp file to our file system, I use that parameter to rename the file in the process of saving it to its "proper" location.

Not beautiful, but it works.



来源:https://stackoverflow.com/questions/36429470/nginx-file-upload-with-client-body-in-file-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!