From 400cb4caf9d2d4fa08c4f552b874b35006dc8c85 Mon Sep 17 00:00:00 2001 From: shaw <53377526+jtcymc@users.noreply.github.com> Date: Fri, 20 Jun 2025 15:44:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(base):=20=E4=BF=AE=E5=A4=8D=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D=E4=B8=AD=E7=9A=84=E4=B8=AD=E6=96=87=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 sanitize_filename 函数中添加 unquote 导入并使用其解码文件名 - 这个修改解决了非 ASCII 字符在文件名中显示为编码形式的问题 - Non-ASCll filename uploads don't comply with RFC 7578 --- apps/base/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/base/utils.py b/apps/base/utils.py index 60a9189..961c399 100644 --- a/apps/base/utils.py +++ b/apps/base/utils.py @@ -2,6 +2,7 @@ import datetime import hashlib import os import uuid +from urllib.parse import unquote from fastapi import UploadFile, HTTPException from typing import Optional, Tuple @@ -17,7 +18,8 @@ async def get_file_path_name(file: UploadFile) -> Tuple[str, str, str, str, str] today = datetime.datetime.now() storage_path = settings.storage_path.strip("/") # 移除开头和结尾的斜杠 file_uuid = uuid.uuid4().hex - filename = await sanitize_filename(file.filename) + # 一些客户端对非ASCII字符会进行编码,需要解码 + filename = await sanitize_filename(unquote(file.filename)) # 使用 UUID 作为子目录名 base_path = f"share/data/{today.strftime('%Y/%m/%d')}/{file_uuid}"