文件名上传修复
This commit is contained in:
parent
55505c727a
commit
82ffe8b623
@ -175,7 +175,9 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
|
|||||||
target_path = resolve_path("projects")
|
target_path = resolve_path("projects")
|
||||||
target_path.mkdir(parents=True, exist_ok=True)
|
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():
|
if file_path.exists():
|
||||||
@ -189,8 +191,9 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
|
|||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": "文件上传成功",
|
"message": "文件上传成功",
|
||||||
"filename": file.filename,
|
"filename": safe_filename,
|
||||||
"path": str(Path(path) / file.filename),
|
"original_filename": file.filename,
|
||||||
|
"path": str(Path(path) / safe_filename),
|
||||||
"size": len(content)
|
"size": len(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user