fix: return binary if not image type, not crash e.g. on svg

This commit is contained in:
Livio Bieri 2024-02-06 15:16:20 +01:00
parent 162f8a50a9
commit bd5cbd3394
1 changed files with 3 additions and 1 deletions

View File

@ -34,6 +34,8 @@ def user_image(request, image_id):
rendition.file.open("rb")
image_format = imghdr.what(rendition.file)
return StreamingHttpResponse(
FileWrapper(rendition.file), content_type="image/" + image_format
FileWrapper(rendition.file),
content_type=f"image/{image_format}" if image_format else "binary/octet-stream",
)