Skip to content

Commit

Permalink
Merge pull request #242 from vin0dkhichar/17.0-1.4-doc-ext
Browse files Browse the repository at this point in the history
Resolved the issue related to file mimetype
  • Loading branch information
shibu-narayanan authored Jan 21, 2025
2 parents c37f5bb + 8882715 commit ad5398d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions g2p_documents/models/document_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def filter_for_tags_any(self, tags):

def _compute_file_type(self):
for file in self:
if file.extension and isinstance(file.mimetype, str):
if isinstance(file.mimetype, str):
file.file_type = file.mimetype.split("/")[1].upper()
else:
file.file_type = False
Expand Down Expand Up @@ -77,11 +77,13 @@ def _compute_extract_filename(self):

def _get_mime_type(self, binary_data):
try:
if binary_data[:4] == b"%PDF":
return "application/pdf"
image = Image.open(io.BytesIO(binary_data))
mime_type = Image.MIME[image.format]
return mime_type
except OSError as e:
_logger.info(f"Image processing error: {e}")
_logger.info(f"Unexpected error in MIME detection: {e}")
return None

def _compute_data(self):
Expand Down

0 comments on commit ad5398d

Please sign in to comment.