fix: 文件下载乱码 — 签名 URL 增加 Content-Disposition: attachment
- generate_presigned_url 支持 download 参数,添加 response-content-disposition - sign-url API 新增 download 查询参数 - 前端 getSignedUrl 支持 download 模式 - 下载时传 download=true,浏览器触发文件保存而非显示乱码 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
0ab58b7e6e
commit
9a0e7b356b
@@ -417,16 +417,8 @@ export default function BriefConfigPage() {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const signedUrl = await api.getSignedUrl(file.url)
|
||||
// 使用 a 标签触发下载
|
||||
const a = document.createElement('a')
|
||||
a.href = signedUrl
|
||||
a.target = '_blank'
|
||||
a.rel = 'noopener noreferrer'
|
||||
a.download = file.name
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
const signedUrl = await api.getSignedUrl(file.url, 3600, true)
|
||||
window.open(signedUrl, '_blank')
|
||||
} catch {
|
||||
toast.error('获取下载链接失败')
|
||||
}
|
||||
@@ -668,15 +660,8 @@ export default function BriefConfigPage() {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const signedUrl = await api.getSignedUrl(file.url)
|
||||
const a = document.createElement('a')
|
||||
a.href = signedUrl
|
||||
a.target = '_blank'
|
||||
a.rel = 'noopener noreferrer'
|
||||
a.download = file.name
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
const signedUrl = await api.getSignedUrl(file.url, 3600, true)
|
||||
window.open(signedUrl, '_blank')
|
||||
} catch {
|
||||
toast.error('获取下载链接失败')
|
||||
}
|
||||
|
||||
+2
-2
@@ -473,10 +473,10 @@ class ApiClient {
|
||||
/**
|
||||
* 获取私有桶文件的预签名访问 URL
|
||||
*/
|
||||
async getSignedUrl(url: string, expire: number = 3600): Promise<string> {
|
||||
async getSignedUrl(url: string, expire: number = 3600, download: boolean = false): Promise<string> {
|
||||
const response = await this.client.get<{ signed_url: string; expire_seconds: number }>(
|
||||
'/upload/sign-url',
|
||||
{ params: { url, expire } }
|
||||
{ params: { url, expire, download } }
|
||||
)
|
||||
return response.data.signed_url
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user