文件名上传修复
This commit is contained in:
commit
6a9003ba77
@ -191,7 +191,10 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
|
|||||||
# 创建目标目录(包括所有不存在的父目录)
|
# 创建目标目录(包括所有不存在的父目录)
|
||||||
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():
|
||||||
@ -218,6 +221,7 @@ async def upload_file(file: UploadFile = File(...), path: str = Form("")):
|
|||||||
|
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"文件上传失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"文件上传失败: {str(e)}")
|
||||||
|
|
||||||
@ -961,4 +965,4 @@ async def batch_operation(operations: List[Dict[str, Any]]):
|
|||||||
}
|
}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"批量操作失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"批量操作失败: {str(e)}")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user