更新文件名字

This commit is contained in:
zoujiandong 2023-11-16 09:56:31 +08:00
parent 576b5807c3
commit e9cedbe908

View File

@ -1,4 +1,7 @@
export const downloadFile=(fileUrl,name='')=>{
let startIndex=fileUrl.indexOf("output");
let endIndex=fileUrl.lastIndexOf(".");
let originName=fileUrl.substring(startIndex,endIndex);
const request = new XMLHttpRequest()
request.open('GET', fileUrl)
request.responseType = 'blob'
@ -6,8 +9,8 @@ export const downloadFile=(fileUrl,name='')=>{
if (res.target.status == 200) {
const url = window.URL.createObjectURL(res.currentTarget.response)
const link = document.createElement('a')
link.href = url
link.setAttribute('download', name+new Date().getTime())
link.href = url;
link.setAttribute('download',originName)
link.click()
}
}