fix: 文件下载改用 fetch+blob 方式,避免浏览器显示乱码
用 fetch 获取文件内容后创建 Blob URL 触发下载, 不依赖服务端 Content-Disposition 头。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9a0e7b356b
commit
0c59797d5b
@ -417,10 +417,19 @@ export default function BriefConfigPage() {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const signedUrl = await api.getSignedUrl(file.url, 3600, true)
|
||||
window.open(signedUrl, '_blank')
|
||||
const signedUrl = await api.getSignedUrl(file.url)
|
||||
const resp = await fetch(signedUrl)
|
||||
const blob = await resp.blob()
|
||||
const blobUrl = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = blobUrl
|
||||
a.download = file.name
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(blobUrl)
|
||||
} catch {
|
||||
toast.error('获取下载链接失败')
|
||||
toast.error('下载失败')
|
||||
}
|
||||
}
|
||||
|
||||
@ -660,10 +669,19 @@ export default function BriefConfigPage() {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const signedUrl = await api.getSignedUrl(file.url, 3600, true)
|
||||
window.open(signedUrl, '_blank')
|
||||
const signedUrl = await api.getSignedUrl(file.url)
|
||||
const resp = await fetch(signedUrl)
|
||||
const blob = await resp.blob()
|
||||
const blobUrl = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = blobUrl
|
||||
a.download = file.name
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(blobUrl)
|
||||
} catch {
|
||||
toast.error('获取下载链接失败')
|
||||
toast.error('下载失败')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user