0

I'm using the twitter node js package at https://github.com/desmondmorris/node-twitter and am running into issues uploading images (posting simple tweet does not cause any issue).

here is my code, note that the first step is downloading the image from S3:

 var Twitter = require('twitter'),
 requestP = require('request-promise-native');

 var twitterConfig = config.twitter;
    twitterConfig.access_token_key = tweet.accessToken;
    twitterConfig.access_token_secret = tweet.accessTokenSecret;
    var twitter;

    // first get the image data
    var promise = requestP(tweet.imageURL)
      .then(imageData => {
        //then the image first
        twitter = new Twitter(twitterConfig);
        return twitter.post("media/upload", {
          media: imageData
        }, function (error, tweets, response) {
          if (!error) {
            console.log(tweets);
          }
        });
      });

I'm getting the following error:"media type unrecognized"

I downloaded the image manually from S3, and it seems valid so i'm unsure what is the issue.

otusweb
  • 1,638
  • 1
  • 19
  • 30

1 Answers1

0

Turns out that to download images with request-promise, I needed to specify that it was binary data.

var promise = requestP({
        uri: tweet.imageURL,
        encoding: null           //note addition here
      })
otusweb
  • 1,638
  • 1
  • 19
  • 30