Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions faraday/server/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

import json
import imghdr
import magic
from tempfile import SpooledTemporaryFile

from PIL import Image
Expand Down Expand Up @@ -47,8 +47,9 @@ class FaradayUploadedFile(UploadedFile):
def process_content(self, content, filename=None, content_type=None):
if isinstance(content, str):
content = content.encode('utf-8')
image_format = imghdr.what(None, h=content[:32])
if image_format:
mime_type = magic.from_buffer(content[:32], mime=True)
if "image" in mime_type:
image_format = mime_type.split('/')[-1]
content_type = f'image/{image_format}'
self.generate_thumbnail(content)
return super().process_content(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ pyotp>=2.6.0
Flask-Limiter
Flask-Mail
faraday_agent_parameters_types>=1.0.3
python-magic-bin==0.4.14