Skip to content

Commit c0984bf

Browse files
authored
Merge pull request #364 from jtcymc/master
fix(base): 修复文件名中的中文编码问题
2 parents 9a80d7a + 62d1a23 commit c0984bf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

apps/base/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import hashlib
33
import os
44
import uuid
5+
from urllib.parse import unquote
56

67
from fastapi import UploadFile, HTTPException
78
from typing import Optional, Tuple
@@ -17,7 +18,8 @@ async def get_file_path_name(file: UploadFile) -> Tuple[str, str, str, str, str]
1718
today = datetime.datetime.now()
1819
storage_path = settings.storage_path.strip("/") # 移除开头和结尾的斜杠
1920
file_uuid = uuid.uuid4().hex
20-
filename = await sanitize_filename(file.filename)
21+
# 一些客户端对非ASCII字符会进行编码,需要解码
22+
filename = await sanitize_filename(unquote(file.filename))
2123
# 使用 UUID 作为子目录名
2224
base_path = f"share/data/{today.strftime('%Y/%m/%d')}/{file_uuid}"
2325

0 commit comments

Comments
 (0)