文件名上传修复

This commit is contained in:
朱潮 2026-03-02 14:29:14 +08:00
commit 6a9003ba77

View File

@ -191,7 +191,10 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
# 创建目标目录(包括所有不存在的父目录)
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():
@ -218,6 +221,7 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=f"文件上传失败: {str(e)}")