Skip to content

Commit

Permalink
gcode downloads
Browse files Browse the repository at this point in the history
ApexArray committed Dec 22, 2023
1 parent c98af03 commit 8c5985a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backend/app/views/web_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mimetypes
import os
from binascii import hexlify
import re
@@ -249,10 +250,16 @@ def serve_jpg_file(request, file_path):
return HttpResponseForbidden("You do not have permission to view this media")
full_path = os.path.join(settings.MEDIA_ROOT, file_path)

# Determine content type based on file extension
content_type = mimetypes.guess_type(file_path)[0]
# Content type is not guessed correctly for files without extensions (i.e. for gcode files), so we set the
# content_type to octet-stream, which initiates a download in the user's browser.
if content_type is None:
content_type = "application/octet-stream"
if not os.path.exists(full_path):
raise Http404("Requested file does not exist")
with open(full_path, 'rb') as fh:
return HttpResponse(fh, content_type=('video/mp4' if file_path.endswith('.mp4') else 'image/jpeg'))
return HttpResponse(fh, content_type=content_type)


# Health check that touches DB and redis

0 comments on commit 8c5985a

Please sign in to comment.