async function DownLoadFile(File: string) {
console.log(File);
if (!File || File == '') return message.warning('暂无可下载文件')
let url = ''
let FileName = ''
try {
const JSONParseFile = JSON.parse(File)
console.log(JSONParseFile);
url = JSONParseFile[0].path
FileName = JSONParseFile[0].name
} catch (error) {
console.log(error);
}
if (!url || url == '') return message.error('下载链接无效')
// window.open(url + `?attname=${FileName}.PDF`, '_blank')
try {
const response = await fetch(url);
const blob = await response.blob();
const blobUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = blobUrl;
a.download = FileName;
a.click();
URL.revokeObjectURL(blobUrl);
} catch (error) {
console.error('文件下载失败:', error);
}
}
React 中下载文件重命名文件名
最新推荐文章于 2025-05-17 19:54:56 发布