文件流下载文件
直接上代码
/*
文件流下载文件
type 必须指定,不然下载的就是TXT
flow 是后端给的文件流 blob
fileName 是下载的文件名称
*/
export const streamingDownload = (flow, fileName, type = “xlsx”) => {
const blob = new Blob([flow]);
const elink = document.createElement(“a”);
elink.download = ${fileName}.${type}
;
elink.style.display = “none”;
elink.href = window.URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
window.URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
};