前端使用a
标签下载图片文件时由于浏览器机制问题致使会直接打开图片连接进行预览。 为了方便,不须要后台进行处理传输文件流返回。因此进行nginx配置,让连接图片在浏览器中直接下载html
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
}
}
复制代码
资源上传后可能在后台是通过特殊处理后存储的,这时候需求提出下载后的资源名称是原来的名称。 经过a
标签的download
属性并不能修更名称,这时候咱们就须要用到nginx
的一个默认配置renameto
达到重置名称的效果。前端
// url为资源地址
// newName为资源的原名称
const tepm = url + '?renameto=' + newName
复制代码