文件名上传修复

This commit is contained in:
朱潮 2026-03-02 14:27:32 +08:00
parent 55505c727a
commit 82ffe8b623

View File

@ -175,7 +175,9 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
target_path = resolve_path("projects")
target_path.mkdir(parents=True, exist_ok=True)
file_path = target_path / file.filename
# 将文件名中的空格替换为下划线
safe_filename = file.filename.replace(" ", "_") if file.filename else file.filename
file_path = target_path / safe_filename
# 如果文件已存在,检查是否覆盖
if file_path.exists():
@ -189,8 +191,9 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
return {
"success": True,
"message": "文件上传成功",
"filename": file.filename,
"path": str(Path(path) / file.filename),
"filename": safe_filename,
"original_filename": file.filename,
"path": str(Path(path) / safe_filename),
"size": len(content)
}