How do I send multiple images to tumblr via their API with Node?

Viewed 128

Tumblr's documentation says that you can send an array or "(URL-encoded binary contents)" in order to post a photo message.

What does "URL-encoded binary contents" actually mean and how do I accomplish this with Node?

I have this function that I've been using to get files from a URL:

function getImage (url) {
  return new RSVP.Promise((resolve, reject) => {
    Request.get({
      url: url,
      encoding: null,
    }, (err, response, body) => {
      if (!err && response && response.statusCode == 200 && body) {
        const buff = Buffer.from(body);
        return resolve(buff.toString()); 
        // I've tried all kinds of stuff here:
        // return resolve(buff.toString('hex')); //nope
        // return resolve(buff.toString('binary')); //nope
        // return resolve(buff.toString('base64')); //nope
        // return resolve(encodeURIComponent(buff.toString('hex')); //nope
        // etc.

      }
    });
  });
};

I then use the result of that function to populate the data parameter of the POST request. I am able to use my POST function to send regular text posts, and image posts if I specify the source (url) of the image rather than the data itself. So I don't think it's an OAuth problem.

The error message I get is:

{
  'meta': {
    'status': 400,
    'msg': 'Bad Request',
  },
  'response': { 'errors': ['Nice image, but we don\'t support that format. Try resaving it as a gif, jpg, or png.'] },
};

I am sending it JPEGs and GIFs, just not in the way they want it. How do I go from the result of a GET to whatever it is that tumblr wants?

0 Answers
Related