From ee2c2194f81c26be4ec315fe1fa64f1bc8667a81 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Mon, 28 Apr 2025 20:36:09 -0500 Subject: [PATCH] Mimetype guessing as a fallback for remote images. --- apps/channels/api_views.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/channels/api_views.py b/apps/channels/api_views.py index 821b0ef4..51952541 100644 --- a/apps/channels/api_views.py +++ b/apps/channels/api_views.py @@ -644,7 +644,18 @@ class LogoViewSet(viewsets.ModelViewSet): try: remote_response = requests.get(logo_url, stream=True) if remote_response.status_code == 200: - response = StreamingHttpResponse(remote_response.iter_content(chunk_size=8192), content_type=remote_response.headers['Content-Type']) + # Try to get content type from response headers first + content_type = remote_response.headers.get('Content-Type') + + # If no content type in headers or it's empty, guess based on URL + if not content_type: + content_type, _ = mimetypes.guess_type(logo_url) + + # If still no content type, default to common image type + if not content_type: + content_type = 'image/jpeg' + + response = StreamingHttpResponse(remote_response.iter_content(chunk_size=8192), content_type=content_type) response['Content-Disposition'] = 'inline; filename="{}"'.format(os.path.basename(logo_url)) return response raise Http404("Remote image not found")