desmondmorris / node-twitter

Client library for the Twitter REST and Streaming API's.
https://www.npmjs.com/package/twitter
MIT License
1.27k stars 238 forks source link

Cant post media using media/upload #328

Closed Jarmahent closed 4 years ago

Jarmahent commented 4 years ago

I am trying to upload an image using a base64 encoded string. I do:

client.post('media/upload', {media_data: mybase64image}, function(error){})

I am recieving this base64 encoded string from a request paramter on my express server, I even did var fixed = req.body.media.toString().replace(/\r?\n|\r/g, '')

To remove any line breaks and twitter still gives me an error. "media type unrecognized"

What am I doing wrong here?

Jarmahent commented 4 years ago

The base64 encoded image needs to have data:image/jpeg;base64 removed in order for twitter to accept it, so I did: var base64Data = encodedImage.replace(/^data:image\/png;base64,/, ""); and it worked!