根据文件对象下载文件

发布时间 2023-06-25 09:52:35作者: Felix_Openmind
const doDownload = (item) => {
    let aUrl = item.address;
    let extNameIcon = item.extName;
    let extName = item.name;
    if (extName.includes(".")) {
        extName = extName.split(".")[0];
    }
    let xml = new XMLHttpRequest();
    xml.open("GET", aUrl, true);
    xml.responseType = "blob";
    xml.onload = () => {
        let url = window.URL.createObjectURL(xml.response);
        let a = document.createElement("a");
        a.href = url;
        a.download = `${extName}.${extNameIcon}`;
        a.style.display = "none";
        a.click();
    };
    xml.send();
};