"media type unrecognized" uploading media to Twitter

I’m trying to upload an image to Twitter using the provided “upload_media_to_twitter” action, and regardless of whether I take the media type from the source data, or provide it manually as a string: “image/png”, I always get the same response:

ErrorRequest failed with status code 400
{
  "request": "/1.1/media/upload.json",
  "error": "media type unrecognized."
}

Any suggestions appreciated!

Here’s an example image that won’t upload: image.png | Slack

Interestingly, if I use a JPEG, such as this one: https://www.nps.gov/common/uploads/structured_data/3C834ED3-1DD8-B71B-0B816A8BE4C5F955.jpg it works fine.

@mbrookes thanks for reaching out. Since that action just wraps the Twitter API, it could be a limitation of Twitter. It could also be a poor error response from Twitter (e.g. the file could be larger than they allow, and the error reason could be incorrect). Have you confirmed they accept any other sample PNG file? You might also reach out to the Twitter Developer forum to see if anyone can help with the details of that API endpoint.

Thanks,
Dylan

Hi Dylan,

Thanks for the reply. A different image, such as this canonical one from Wikipedia does work. Both are a similar size though (50-60KB) and well under the 2MB Twitter limit.

If I download the failing image, I can upload it as part of a tweet via the Twitter web client no problem. The only difference is that that’s using https://upload.twitter.com/i/media/upload.json rather than https://upload.twitter.com/1.1/media/upload.json. (Trying /i/ in the script naturally returns a 403).

So:
Not the API/script - it works with another image.
Not the file size - it’s tiny.
Not the file format - it works when uploaded directly.

I’m at a loss.