@@ -571,7 +571,7 @@ def __init__(self):
571571 self ._initialized = True
572572
573573 def _build_url (self , path : str ) -> str :
574- encoded_path = quote (str (path ).lstrip ("/" ))
574+ encoded_path = quote (str (path . replace ( " \\ " , "/" ). lstrip ( "/" ) ).lstrip ("/" ))
575575 return f"{ self .base_url } { encoded_path } "
576576
577577 async def _mkdir_p (self , directory_path : str ):
@@ -630,11 +630,9 @@ async def save_file(self, file: UploadFile, save_path: str):
630630 # 分离文件名和目录路径
631631 path_obj = Path (save_path )
632632 directory_path = str (path_obj .parent )
633-
634633 try :
635634 # 先创建目录结构
636635 await self ._mkdir_p (directory_path )
637-
638636 # 上传文件
639637 url = self ._build_url (save_path )
640638 async with aiohttp .ClientSession (auth = self .auth ) as session :
@@ -690,7 +688,7 @@ async def get_file_response(self, file_code: FileCodes):
690688 if resp .status != 200 :
691689 raise HTTPException (
692690 status_code = resp .status ,
693- detail = f"文件获取失败: { await resp .text ()} " ,
691+ detail = f"文件获取失败{ resp . status } : { await resp .text ()} " ,
694692 )
695693 # 读取内容到内存
696694 content = await resp .read ()
@@ -708,8 +706,7 @@ async def get_file_response(self, file_code: FileCodes):
708706 status_code = 503 , detail = f"WebDAV连接异常: { str (e )} " )
709707
710708 async def save_chunk (self , upload_id : str , chunk_index : int , chunk_data : bytes , chunk_hash : str , save_path : str ):
711- chunk_path = str (Path (save_path ).parent / "chunks" /
712- upload_id / f"{ chunk_index } .part" )
709+ chunk_path = str (Path (save_path ).parent / "chunks" / upload_id / f"{ chunk_index } .part" )
713710 chunk_url = self ._build_url (chunk_path )
714711 async with aiohttp .ClientSession (auth = self .auth ) as session :
715712 await session .put (chunk_url , data = chunk_data )
0 commit comments