a標籤下載圖片,配置資源文件(圖片、視頻等)文件連接在瀏覽器中直接下載

前言

前端使用a標籤下載圖片文件時由於瀏覽器機制問題致使會直接打開圖片連接進行預覽。
爲了方便,不須要後臺進行處理傳輸文件流返回。因此進行nginx配置,讓連接圖片在瀏覽器中直接下載html

nginx配置信息

server {
        listen 8086;
        server_name 192.168.1.66;
        location / {
            proxy_pass http://127.0.0.1:8086;
            root html;
            index index.html index.htm;
        }
        location /image/ {
            root html/devGif;
            autoindex on;
            // 主要配置
             if ($request_filename ~* ^.*?.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx|jpg|png)$){
               add_header Content-Disposition 'attachment';
            }
        //end
        }
}
相關文章
相關標籤/搜索