类似于这个链接,一点开是个文件下载(下载zip文件)
https://itmp-test.testdolphin.com/ga-hy-api/haiyan-server/resource/normal-export/image/get?filename=diyVehicleImage20231030094237.zip
a链接直接href跳转的话
下载的文件名前缀跟想要的不一样,文件名是不带_data_private的
页面中把a标签注释,给img添加点击函数
绑定这个函数
downLoadImg (url, fileName){
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.onload = function() {
if (this.status === 200) {
var blob = new Blob([this.response]);
var blobUrl = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = blobUrl;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(blobUrl);
}
};
xhr.send();
},
url:就是这样的可以直接下载的:https://itmp-test.testdolphin.com/ga-hy-api/haiyan-server/resource/normal-export/image/get?filename=diyVehicleImage20231030094237.zip
fileName:想要改的文件名