axios({
url: `${baseURL}workplan/workPlanController/api/searchFilesTempByRegisterId?id=${id}`,
method: 'GET',
responseType:"blob"
}).then((res) => {
// 文件名称处理
let filename = res.headers['content-type']
let index = filename.indexOf("=")
let name = decodeURI(filename.substr(index + 1,filename.length).split('.')[0])
// 文件类型处理
let type = filename.substr(index + 1,filename.length).split('.')[1].split(';')[0]
let blob = new Blob([res.data],{
type:'application/pdf'
});
let url = window.URL.createObjectURL(blob)
let a = document.createElement("a");
a.href = url;
// 名称和类型拼接
a.download = `${name}.${type}`;
a.click();
// 5.释放这个临时的对象url
window.URL.revokeObjectURL(url);
})
.catch((err) => {
})
前端处理Blob文件流
最新推荐文章于 2024-04-09 09:35:48 发布