@@ -571,7 +571,7 @@ def __init__(self):
571
571
self ._initialized = True
572
572
573
573
def _build_url (self , path : str ) -> str :
574
- encoded_path = quote (str (path ).lstrip ("/" ))
574
+ encoded_path = quote (str (path . replace ( " \\ " , "/" ). lstrip ( "/" ) ).lstrip ("/" ))
575
575
return f"{ self .base_url } { encoded_path } "
576
576
577
577
async def _mkdir_p (self , directory_path : str ):
@@ -630,11 +630,9 @@ async def save_file(self, file: UploadFile, save_path: str):
630
630
# 分离文件名和目录路径
631
631
path_obj = Path (save_path )
632
632
directory_path = str (path_obj .parent )
633
-
634
633
try :
635
634
# 先创建目录结构
636
635
await self ._mkdir_p (directory_path )
637
-
638
636
# 上传文件
639
637
url = self ._build_url (save_path )
640
638
async with aiohttp .ClientSession (auth = self .auth ) as session :
@@ -690,7 +688,7 @@ async def get_file_response(self, file_code: FileCodes):
690
688
if resp .status != 200 :
691
689
raise HTTPException (
692
690
status_code = resp .status ,
693
- detail = f"文件获取失败: { await resp .text ()} " ,
691
+ detail = f"文件获取失败{ resp . status } : { await resp .text ()} " ,
694
692
)
695
693
# 读取内容到内存
696
694
content = await resp .read ()
@@ -708,8 +706,7 @@ async def get_file_response(self, file_code: FileCodes):
708
706
status_code = 503 , detail = f"WebDAV连接异常: { str (e )} " )
709
707
710
708
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" )
713
710
chunk_url = self ._build_url (chunk_path )
714
711
async with aiohttp .ClientSession (auth = self .auth ) as session :
715
712
await session .put (chunk_url , data = chunk_data )
0 commit comments