From 34e36944bd149a81c4ffa44dc0eaf5262dce169d Mon Sep 17 00:00:00 2001 From: jerryliang Date: Fri, 16 Jan 2026 16:44:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E6=89=80=E6=9C=89=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E5=AE=9E=E7=8E=B0=E4=B8=AD=E6=B7=BB=E5=8A=A0Content-L?= =?UTF-8?q?ength=E5=93=8D=E5=BA=94=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/storage.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/core/storage.py b/core/storage.py index a459797..707ff91 100644 --- a/core/storage.py +++ b/core/storage.py @@ -147,7 +147,7 @@ class SystemFileStorage(FileStorageInterface): return FileResponse( file_path, media_type="application/octet-stream", - headers={"Content-Disposition": content_disposition}, + headers={"Content-Disposition": content_disposition, "Content-Length": str(file_code.size)}, filename=filename # 保留原始文件名以备某些场景使用 ) @@ -329,7 +329,8 @@ class S3FileStorage(FileStorageInterface): from fastapi.responses import StreamingResponse headers = { - "Content-Disposition": f'attachment; filename="{filename.encode("utf-8").decode("latin-1")}"' + "Content-Disposition": f'attachment; filename="{filename.encode("utf-8").decode("latin-1")}"', + "Content-Length": str(file_code.size) } return StreamingResponse( stream_generator(), @@ -633,7 +634,8 @@ class OneDriveFileStorage(FileStorageInterface): yield chunk headers = { - "Content-Disposition": f'attachment; filename="{filename.encode("utf-8").decode("latin-1")}"' + "Content-Disposition": f'attachment; filename="{filename.encode("utf-8").decode("latin-1")}"', + "Content-Length": str(file_code.size) } return StreamingResponse( stream_generator(), @@ -810,7 +812,8 @@ class OpenDALFileStorage(FileStorageInterface): # 如果 reader 方法不存在,回退到全量读取(兼容旧版本) content = await self.operator.read(await file_code.get_file_path()) headers = { - "Content-Disposition": f'attachment; filename="{filename}"' + "Content-Disposition": f'attachment; filename="{filename}"', + "Content-Length": str(file_code.size) } return Response( content, headers=headers, media_type="application/octet-stream" @@ -825,7 +828,8 @@ class OpenDALFileStorage(FileStorageInterface): yield chunk headers = { - "Content-Disposition": f'attachment; filename="{filename}"' + "Content-Disposition": f'attachment; filename="{filename}"', + "Content-Length": str(file_code.size) } return StreamingResponse( stream_generator(), @@ -1038,7 +1042,8 @@ class WebDAVFileStorage(FileStorageInterface): yield chunk headers = { - "Content-Disposition": f'attachment; filename="{filename.encode("utf-8").decode()}"' + "Content-Disposition": f'attachment; filename="{filename.encode("utf-8").decode()}"', + "Content-Length": str(file_code.size) } return StreamingResponse( stream_generator(),