0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-30 01:46:24 +01:00

Replace imghdr with Willow's built-in mime-type detection

This commit is contained in:
Jake Howard 2023-09-05 12:28:01 +01:00 committed by LB (Ben Johnston)
parent 19b4df2648
commit 2ec1b0314b

View File

@ -1,4 +1,3 @@
import imghdr
from wsgiref.util import FileWrapper
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
@ -64,11 +63,13 @@ class ServeView(View):
return getattr(self, self.action)(rendition)
def serve(self, rendition):
with rendition.get_willow_image() as willow_image:
mime_type = willow_image.mime_type
# Open and serve the file
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=mime_type
)
def redirect(self, rendition):