fix(media): Add debug logging for unrecognized image formats - v1.4.2
Logs magic bytes when both Pillow and HEIC parsers fail, to help diagnose what format the file actually is. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -121,7 +121,16 @@ def validate_image(file_data: bytes, filename: str) -> Tuple[bytes, str, int, in
|
||||
)
|
||||
# Mark as HEIF so conversion happens below
|
||||
img.format = 'HEIF'
|
||||
except Exception:
|
||||
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}")
|
||||
|
||||
Reference in New Issue
Block a user