You've already forked DataMate
fix(annotation): 解决文件名中文编码问题
- 添加 urllib.parse.quote 用于文件名编码 - 实现 RFC 5987 标准支持 UTF-8 编码的文件名 - 修改 Content-Disposition 头部使用 filename* 参数 - 确保中文文件名在下载时正确显示
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from urllib.parse import quote
|
||||
|
||||
from fastapi import APIRouter, Depends, Path, Query
|
||||
from fastapi.responses import Response
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
@@ -79,11 +81,15 @@ async def download_annotations(
|
||||
request=request,
|
||||
)
|
||||
|
||||
# RFC 5987: 使用 filename* 支持 UTF-8 编码的文件名
|
||||
encoded_filename = quote(filename, safe="")
|
||||
content_disposition = f"attachment; filename*=UTF-8''{encoded_filename}"
|
||||
|
||||
return Response(
|
||||
content=content,
|
||||
media_type=content_type,
|
||||
headers={
|
||||
"Content-Disposition": f'attachment; filename="{filename}"',
|
||||
"Content-Disposition": content_disposition,
|
||||
"Content-Length": str(len(content)),
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user