"media/upload" error when uploading base-64-encoded images


#1

Hello,
I’m pretty sure this is a bug and i already wrote this to @twitterdev but was told to post it here.

When you want to upload an image to the media/upload endpoint (to use it for extended entities) the documentation states that you can encode the image in base-64 but then have to use the param “media_data” instead of “media”.
But if you do as said, the API returns an error: "media param has zero bytes."
Since the media param should have zero bytes when uploading base-64 images (if i understand the documentation correctly) this seems to be a bug.

I tested this in my app and via twurl:

twurl -H upload.twitter.com "/1.1/media/upload.json" -d "type=photo" -f ~/my/image.png -b -F "media_data" -X POST

I hope you can fix this or tell me what i’m doing wrong ^^


#2

Hello,

Thanks for the question. Would you like to upload an image file or the base64 string directly?

The reason I’m asking is because in the command you shared, you are using the path to a local image, so I think you should use the one below instead with the media parameter instead of media_data in that case:

twurl -H upload.twitter.com "/1.1/media/upload.json" -f ~/my/image.png -F media -X POST

Let us know if this helps fixing your issue!

Thanks,
Romain


#3

First off, thanks for the quick reply!

I want to upload the base64 string directly in my app. That’s why i added the -b flag in my twurl command which does the following:

-b, --base64  Encode the uploaded file as base64 (default: false)

But even if this option does not provide the string as i thought, if i try it manually (with a setted base64 string in media_data) it doesn’t work either.
And no matter what i put into media_data it always returns the quoted error which seems wrong, because, how i said, when uploading a base64-encoded image the media param should be empty, shouldn’t it?


#4

@romainhuet I’m looking into similar features and finding it difficult to come up with the correct combination of parameters with twurl. How does one using twurl send direct message with media attached? I’m using the following command but only the status message gets sent. No image is shown to the user.

./bin/twurl “/1.1/statuses/update_with_media.json” -f ~/Desktop/Avatar.jpg -F media -X POST -t -d “status=d @romainhuet test”


#5

Twitter Staff respond to this? I’m also not able to upload Base64 images using the new endpoint.


#6

is was trying to upload base64 directly. I am getting response

401
{“errors”:[{“message”:“Could not authenticate you”,“code”:32}]}.

Can anyone please let me know solution.


#7

It is not currently possible to post direct messages with media attachments via the API.


#8

I am using below API.
@andypiper
https://dev.twitter.com/rest/public/uploading-media-multiple-photos


#9

This is now fixed (we didn’t support base64-encoded images on this endpoint prior to today):

Support for base64-encoded media on our POST media/uplaod endpoint is now supported. You’ll want to use the new media_data field for base64-encoded media, and continue to use the media field for raw uploads.


Uploading Base64 Encoded Image using /1.1/media/upload.json
#10

Will use media_data per the advice above, but in troubleshooting another issue I noticed that both media and media_data both work with base64.


#11

I am using https://www.npmjs.com/package/node-twitter-api library in nodejs. The Authentication is successfull but I get “media type unrecognized” error while uploading media(both jpeg/png format) with base64-encoded string.
Can anyone help me out with this?