前端下载文件流
【代码】前端下载文件流。
·
const sessionData: any = sessionStorage.getItem("token");
const tokenHead: any = sessionStorage.getItem("headerType");
let params = {
fileInfoId: row.fileInfoId,
id: row.id,
name: row.name,
};
axios({
method: "post",
url: apiConstatns.URL.META_BASE.FILE_DOWNDILE,
data: params,
responseType: "blob",
headers: { Authorization: tokenHead + sessionData },
}).then((res: any) => {
let blob = new Blob([res.data], { type: "application/octet-stream" });
const downloadElement = document.createElement("a");
const headers = res.headers;
const fileName = filterDate(row.createTime) + row.name;
downloadElement.download = fileName;
downloadElement.href = URL.createObjectURL(blob);
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
});
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)