From b16c53767b2f1743649423e88d797d9e037b66a7 Mon Sep 17 00:00:00 2001 From: Pavlo Mokiichuk Date: Wed, 13 Nov 2024 12:21:26 +0100 Subject: [PATCH] [STG] Fix download file for stg/dev env (#4423) * fix download file * mypy * upd download * upd --- src/hct_mis_api/apps/payment/api/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hct_mis_api/apps/payment/api/views.py b/src/hct_mis_api/apps/payment/api/views.py index 2f610c8b82..bc23941961 100644 --- a/src/hct_mis_api/apps/payment/api/views.py +++ b/src/hct_mis_api/apps/payment/api/views.py @@ -210,7 +210,10 @@ def destroy(self, request: Request, *args: Any, **kwargs: Any) -> Response: @action(detail=True, methods=["get"]) def download(self, request: Request, *args: Any, **kwargs: Any) -> FileResponse: document = self.get_object() - file_mimetype, _ = mimetypes.guess_type(document.file.path) - response = FileResponse(document.file.open(), content_type=file_mimetype or "application/octet-stream") - response["Content-Disposition"] = f"attachment; filename={document.file.name.split('/')[-1]}" + file = document.file + file_mimetype, _ = mimetypes.guess_type(file.url) + response = FileResponse( + file.open(), as_attachment=True, content_type=file_mimetype or "application/octet-stream" + ) + response["Content-Disposition"] = f"attachment; filename={file.name.split('/')[-1]}" return response