-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Gracefully handle failing to thumbnail images #16211
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fix bug where uploading images would fail if we could not generate thumbanils for them. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's a truncated JPEG? E.g. we only have the first say 60% of the JPEG file?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, which turns out to be relatively common for reasons beyond understanding. |
||
| 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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a warning? It is tough though since it is user content, what's an admin to do? I think catching the error and having the image uploaded even if thumbnails fail is the correct thing to do though!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW my model of warning is "something went wrong, but it wasn't our fault". I can see this one going either way; no strong opinions from me. |
||
|
|
||
| return MXCUri(self.server_name, media_id) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.