vue 根据文件url 下载文件
·
async handleCheckFile (row) {
const fileUrl = row.fileUrl // 这个文件url 浏览器可以直接打开的 不是文件流也不是返回文件流的接口
const fileName = row.fileName; // 支持自定义的文件名
try {
const response = await axios.get(fileUrl, { responseType: 'blob' });
const contentType = response.headers['content-type'];
const blob = new Blob([response.data], { type: contentType });
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// 兼容IE浏览器
window.navigator.msSaveBlob(blob, fileName);
} else {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', fileName);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}
} catch (error) {
console.error('Error downloading file:', error);
}
// this.detailFun(row);
},
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)