Skip to content

Commit

Permalink
upd download
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlo-mk committed Nov 12, 2024
1 parent 611b384 commit 7fb72ba
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/hct_mis_api/apps/payment/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from django.db.models import QuerySet
from django.http import FileResponse

import requests
from constance import config
from django_filters import rest_framework as filters
from rest_framework import mixins, status
Expand Down Expand Up @@ -211,9 +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_url = document.file.url
file_mimetype, _ = mimetypes.guess_type(file_url)
resp = requests.get(file_url, stream=True)
response = FileResponse(resp.raw, 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(
document.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 7fb72ba

Please sign in to comment.