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
@@ -135,6 +135,7 @@ class SignedUrlResponse(BaseModel):
|
||||
async def get_signed_url(
|
||||
url: str = Query(..., description="文件的原始 URL 或 file_key"),
|
||||
expire: int = Query(3600, ge=60, le=43200, description="有效期(秒),默认1小时,最长12小时"),
|
||||
download: bool = Query(False, description="是否强制下载(添加 Content-Disposition: attachment)"),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
@@ -157,7 +158,7 @@ async def get_signed_url(
|
||||
)
|
||||
|
||||
try:
|
||||
signed_url = generate_presigned_url(file_key, expire_seconds=expire)
|
||||
signed_url = generate_presigned_url(file_key, expire_seconds=expire, download=download)
|
||||
except ValueError as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user