@@ -354,8 +354,9 @@ async def stream_generator():
354354 yield chunk
355355
356356 from fastapi .responses import StreamingResponse
357+ encoded_filename = quote (filename , safe = '' )
357358 headers = {
358- "Content-Disposition" : f' attachment; filename=" { filename . encode ( "utf-8" ). decode ( "latin-1" ) } "' ,
359+ "Content-Disposition" : f" attachment; filename*=UTF-8'' { encoded_filename } " ,
359360 "Content-Length" : str (content_length )
360361 }
361362 return StreamingResponse (
@@ -671,8 +672,9 @@ async def stream_generator():
671672 break
672673 yield chunk
673674
675+ encoded_filename = quote (filename , safe = '' )
674676 headers = {
675- "Content-Disposition" : f' attachment; filename=" { filename . encode ( "utf-8" ). decode ( "latin-1" ) } "' ,
677+ "Content-Disposition" : f" attachment; filename*=UTF-8'' { encoded_filename } " ,
676678 "Content-Length" : str (content_length )
677679 }
678680 return StreamingResponse (
@@ -862,8 +864,9 @@ async def get_file_response(self, file_code: FileCodes):
862864 except AttributeError :
863865 # 如果 reader 方法不存在,回退到全量读取(兼容旧版本)
864866 content = await self .operator .read (await file_code .get_file_path ())
867+ encoded_filename = quote (filename , safe = '' )
865868 headers = {
866- "Content-Disposition" : f' attachment; filename=" { filename } "' ,
869+ "Content-Disposition" : f" attachment; filename*=UTF-8'' { encoded_filename } " ,
867870 "Content-Length" : str (content_length )
868871 }
869872 return Response (
@@ -878,8 +881,9 @@ async def stream_generator():
878881 break
879882 yield chunk
880883
884+ encoded_filename = quote (filename , safe = '' )
881885 headers = {
882- "Content-Disposition" : f' attachment; filename=" { filename } "' ,
886+ "Content-Disposition" : f" attachment; filename*=UTF-8'' { encoded_filename } " ,
883887 "Content-Length" : str (content_length )
884888 }
885889 return StreamingResponse (
@@ -1105,8 +1109,9 @@ async def stream_generator():
11051109 break
11061110 yield chunk
11071111
1112+ encoded_filename = quote (filename , safe = '' )
11081113 headers = {
1109- "Content-Disposition" : f' attachment; filename=" { filename . encode ( "utf-8" ). decode () } "' ,
1114+ "Content-Disposition" : f" attachment; filename*=UTF-8'' { encoded_filename } " ,
11101115 "Content-Length" : str (content_length )
11111116 }
11121117 return StreamingResponse (
0 commit comments