Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Gracefully handle failing to thumbnail images (#16211)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston authored Aug 30, 2023
1 parent a2e0d4c commit 3de82bb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/16211.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where uploading images would fail if we could not generate thumbnails for them.
5 changes: 5 additions & 0 deletions synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
import sys
from typing import Any, Dict

from PIL import ImageFile

from synapse.util.rust import check_rust_lib_up_to_date
from synapse.util.stringutils import strtobool

# Allow truncated JPEG images to be thumbnailed.
ImageFile.LOAD_TRUNCATED_IMAGES = True

# Check that we're not running on an unsupported Python version.
#
# Note that we use an (unneeded) variable here so that pyupgrade doesn't nuke the
Expand Down
5 changes: 4 additions & 1 deletion synapse/media/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ async def create_content(
user_id=auth_user,
)

await self._generate_thumbnails(None, media_id, media_id, media_type)
try:
await self._generate_thumbnails(None, media_id, media_id, media_type)
except Exception as e:
logger.info("Failed to generate thumbnails: %s", e)

return MXCUri(self.server_name, media_id)

Expand Down

0 comments on commit 3de82bb

Please sign in to comment.