Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluesky Publish: PIL.UnidentifiedImageError on SVG image #1866

Open
snarfed opened this issue Dec 17, 2024 · 2 comments
Open

Bluesky Publish: PIL.UnidentifiedImageError on SVG image #1866

snarfed opened this issue Dec 17, 2024 · 2 comments

Comments

@snarfed
Copy link
Owner

snarfed commented Dec 17, 2024

Got a live one! Looks like PIL doesn't support SVGs. @JoelOtter I don't think Bluesky itself does either, so we probably just want to catch this error and return 400...? Lmk what you think!

https://uploads.catgirlin.space/2024/12_17/c088c706642b9b4240526daeb23fbb0cdcc958ff.svg

Traceback (most recent call last):
...
  File "/workspace/publish.py", line 712, in dispatch_request
    result = self._run()
             ^^^^^^^^^^^
  File "/workspace/publish.py", line 238, in _run
    result = self.attempt_single_item(item)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/publish.py", line 399, in attempt_single_item
    result = self.source.gr_source.create(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/granary/bluesky.py", line 2051, in create
    return self._create(obj, preview=False, include_link=include_link,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/granary/bluesky.py", line 2190, in _create
    blobs, aspects = self.upload_media(images)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/granary/bluesky.py", line 2279, in upload_media
    with Image.open(data) as image:
         ^^^^^^^^^^^^^^^^
  File "/layers/google.python.pip/pip/lib/python3.12/site-packages/PIL/Image.py", line 3536, in open
    raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x3e9ee4155a80>

https://console.cloud.google.com/errors/detail/CPTG2ICc7JzeJw;locations=global;time=P30D?project=brid-gy

@JoelOtter
Copy link
Contributor

Yeah let's just create an allow list of formats. JPEG, PNG? The Bluesky app will upload a SVG but it converts it to a JPEG on (presumably) the client-side.

Additionally I did just notice the Bluesky docs say it's up to clients to strip EXIF data from photos, should we do that or do you think Bridgy users will largely be OK with EXIF data going to Bluesky if it's on their public website already?

@snarfed
Copy link
Owner Author

snarfed commented Dec 17, 2024

Hmm! I guess we could allowlist formats, but we could also just catch this exception? Might be easier and more forward compatible and also handle other errors we haven't thought about yet.

As for EXIF, I don't feel strongly, but I'd lean toward leaving it in. Open to other thoughts though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants