Media Upload with API 1.1


#1

I’m using:

Twitter REST API 1.1 /media/upload
Node.js
npm node-twitter
Client Side: angular.js (not relevant to the example am posting below)

I guess ‘node-twitter’ uses base URL as api.twitter.com but for media upload the base URL is upload.twitter.com - am not 100% sure about how ‘node-twitter’ package handles all these. But after working with it for sometime I feel it’s REST API base URL is set as api.twitter.com

router.get('/api/media/upload', function(req, res){
    var fs = require('fs');
    twit.post('/media/upload', {media: fs.readFileSync('C:/Users/Satish/Downloads/243515_183060768410422_4955904_o.jpg', { encoding: 'base64' })}, function(error, params, response){
            if(error) console.log(error);
            else {
           twit.post('/statuses/update', {status: 'hello world!', media_ids: [params.media_id]}, function(error, params, response){
          console.log(params);
          res.json(params);
      });
       }
  });
});

But this code is throughing error, stating - 404, page does not exist. My guess is, ‘node-twitter’ is considering api.twitter.com as base URL for /media/upload too. If I replace ‘/media/upload’ with full URL ‘https://upload.twitter.com/1.1/media/upload’ still I get the same error message :frowning:

[Most of the articles online are written for deprecated POST statuses/update_with_media ]


#2

I had a quick look to the source code and it seem they handle it properly:

// If the path begins with media or /media
    if (path.match(/^(\/)?media/)) {
      endpoint = bases.media;
    }

I can’t find any obvious error in your code, I think it should work…