Compare commits
2 Commits
v1.4.2-rc.
...
v1.4.2-rc.
| Author | SHA1 | Date | |
|---|---|---|---|
| e8ff0a0dcb | |||
| 9bc6780a8e |
@@ -108,6 +108,31 @@ def validate_image(file_data: bytes, filename: str) -> Tuple[bytes, str, int, in
|
|||||||
# Re-open after verify (verify() closes the file)
|
# Re-open after verify (verify() closes the file)
|
||||||
img = Image.open(io.BytesIO(file_data))
|
img = Image.open(io.BytesIO(file_data))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
# v1.4.2: If Pillow can't open, try explicitly as HEIC
|
||||||
|
# iOS sometimes saves HEIC with .jpeg extension
|
||||||
|
if HEIC_SUPPORTED:
|
||||||
|
try:
|
||||||
|
heif_file = pillow_heif.read_heif(file_data)
|
||||||
|
img = Image.frombytes(
|
||||||
|
heif_file.mode,
|
||||||
|
heif_file.size,
|
||||||
|
heif_file.data,
|
||||||
|
"raw",
|
||||||
|
)
|
||||||
|
# Mark as HEIF so conversion happens below
|
||||||
|
img.format = 'HEIF'
|
||||||
|
except Exception as heic_error:
|
||||||
|
# Log the magic bytes for debugging (if in app context)
|
||||||
|
try:
|
||||||
|
magic = file_data[:12].hex() if len(file_data) >= 12 else file_data.hex()
|
||||||
|
current_app.logger.warning(
|
||||||
|
f'Media upload failed both Pillow and HEIC: filename="{filename}", '
|
||||||
|
f'magic_bytes={magic}, pillow_error="{e}", heic_error="{heic_error}"'
|
||||||
|
)
|
||||||
|
except RuntimeError:
|
||||||
|
pass # Outside app context (e.g., tests)
|
||||||
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
|
else:
|
||||||
raise ValueError(f"Invalid or corrupted image: {e}")
|
raise ValueError(f"Invalid or corrupted image: {e}")
|
||||||
|
|
||||||
# HEIC/HEIF conversion (v1.4.2)
|
# HEIC/HEIF conversion (v1.4.2)
|
||||||
|
|||||||
Reference in New Issue
Block a user