Skip to content

Commit

Permalink
Added mime type
Browse files Browse the repository at this point in the history
  • Loading branch information
remyvdwereld committed Nov 2, 2024
1 parent 4a8b675 commit e9f4c55
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/apps/cases/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mimetypes
from apps.homeownerassociation.models import Contact
from apps.events.serializers import CaseEventSerializer
from apps.events.mixins import CaseEventsMixin
Expand Down Expand Up @@ -80,8 +81,13 @@ def get_documents(self, request, pk=None):
def download_document(self, request, pk=None, doc_id=None):
case = self.get_object()
case_document = get_object_or_404(CaseDocument, case=case, id=doc_id)
with default_storage.open(case_document.document.name, "rb") as file:
response = FileResponse(file, content_type="application/octet-stream")
file_path = case_document.document.name
# Add the mime type so the frontend knows how to handle the file.
mime_type, _ = mimetypes.guess_type(file_path)
content_type = mime_type or "application/octet-stream"

with default_storage.open(file_path, "rb") as file:
response = FileResponse(file, content_type=content_type)
response["Content-Disposition"] = (
f'attachment; filename="{case_document.document.name}"'
)
Expand Down

0 comments on commit e9f4c55

Please sign in to comment.