标签(空格分隔): js
先试试这个方法(支持低版本chrome浏览器,高版本不行)
/**
*
* @param {*} path src路径 imgName 图片名称
*/
function downloadImage(path,imgName) {
var $a = $("<a></a>").attr("href", _OBJECT_URL).attr("download", imgName);
$a[0].click();
}
如果上述方法不行,试试这个
基础
1)nginx 要配置反向代理
location /data {
proxy_pass http://172.160.230.168:8086/data;//服务器地址
}
2)path 路径为 本地回环地址
eg:http://127.0.0.1:8888/data/evpl/20190123/dfa111b0945d4916b04e2845e749a1bc/image/88c21a4543d74a2987c240b78011696c/Hydrangeas.jpg
/**
*
* @param {*} path src本地回环地址 imgName 图片名称
*/
function downloadImage(path,imgName) {
var _OBJECT_URL;
var request = new XMLHttpRequest();
request.addEventListener('readystatechange', function (e) {
if (request.readyState == 4) {
_OBJECT_URL = URL.createObjectURL(request.response);
var $a = $("<a></a>").attr("href", _OBJECT_URL).attr("download", imgName);
$a[0].click();
}
});
request.responseType = 'blob';
request.open('get', path);
request.send();
}
网友评论