Skip to content

Commit

Permalink
[STG] Fix download file for stg/dev env (#4423)
Browse files Browse the repository at this point in the history
* fix download file

* mypy

* upd download

* upd
  • Loading branch information
pavlo-mk authored Nov 13, 2024
1 parent 62d4c76 commit b16c537
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/hct_mis_api/apps/payment/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b16c537

Please sign in to comment.