bridgy icon indicating copy to clipboard operation
bridgy copied to clipboard

Bluesky Publish: PIL.UnidentifiedImageError on SVG image

Open snarfed opened this issue 1 year ago • 2 comments

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

snarfed avatar Dec 17 '24 15:12 snarfed

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?

JoelOtter avatar Dec 17 '24 19:12 JoelOtter

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!

snarfed avatar Dec 17 '24 20:12 snarfed