下载文件改名
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
13f105faa5
commit
81506cc337
|
@ -24,18 +24,20 @@ export const downloadImage = async (id, id2, IsDicom = true) => {
|
||||||
}
|
}
|
||||||
let a = document.createElement("a");
|
let a = document.createElement("a");
|
||||||
let href = Vue.prototype.OSSclientConfig.basePath + res.Result;
|
let href = Vue.prototype.OSSclientConfig.basePath + res.Result;
|
||||||
// let fileName =
|
download(href, res.OtherInfo.FileName)
|
||||||
// res.Result.split("/")[res.Result.split("/").length - 1];
|
|
||||||
a.download = res.OtherInfo.fileName;
|
|
||||||
a.href = href;
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(href);
|
|
||||||
let timer = setTimeout(() => {
|
|
||||||
a = null;
|
|
||||||
href = null;
|
|
||||||
timer = null;
|
|
||||||
}, 500)
|
|
||||||
return 2;
|
return 2;
|
||||||
|
// // let fileName =
|
||||||
|
// // res.Result.split("/")[res.Result.split("/").length - 1];
|
||||||
|
// a.download = res.OtherInfo.FileName;
|
||||||
|
// a.href = href;
|
||||||
|
// a.click();
|
||||||
|
// URL.revokeObjectURL(href);
|
||||||
|
// let timer = setTimeout(() => {
|
||||||
|
// a = null;
|
||||||
|
// href = null;
|
||||||
|
// timer = null;
|
||||||
|
// }, 500)
|
||||||
|
// return 2;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -142,4 +144,46 @@ export const fileDownload = (content, filename) => {
|
||||||
document.body.appendChild(eleLink);
|
document.body.appendChild(eleLink);
|
||||||
eleLink.click();
|
eleLink.click();
|
||||||
document.body.removeChild(eleLink);
|
document.body.removeChild(eleLink);
|
||||||
};
|
};
|
||||||
|
let download = async (downloadUrl, downloadFileName) => {
|
||||||
|
const blob = await getBlob(downloadUrl);
|
||||||
|
saveAsB(blob, downloadFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
let getBlob = (url) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
xhr.open('GET', url, true);
|
||||||
|
xhr.responseType = 'blob';
|
||||||
|
xhr.onload = () => {
|
||||||
|
if (xhr.status === 200) {
|
||||||
|
resolve(xhr.response);
|
||||||
|
} else {
|
||||||
|
reject(new Error(`Request failed with status ${xhr.status}`));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.onerror = () => {
|
||||||
|
reject(new Error('Request failed'));
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let saveAsB = (blob, filename) => {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
const body = document.body;
|
||||||
|
|
||||||
|
link.href = window.URL.createObjectURL(blob);
|
||||||
|
link.download = filename;
|
||||||
|
|
||||||
|
// hide the link
|
||||||
|
link.style.display = 'none';
|
||||||
|
body.appendChild(link);
|
||||||
|
|
||||||
|
link.click();
|
||||||
|
body.removeChild(link);
|
||||||
|
|
||||||
|
window.URL.revokeObjectURL(link.href);
|
||||||
|
}
|
Loading…
Reference in New Issue