title: Twitter API: media/upload 400 Bad Request: media type unrecognized
body: <p>So I've got a website where a user uploads an image file (I've been testing with a 113KB PNG file). After hitting the submit button, the image data gets encoded into base64 and then is sent to a node.js server hosted on heroku in a JSON in the body of the POST request. The server then takes the image data and parses the JSON. Then, I make a POST from the heroku server to the <code>media/upload</code> endpoint using the node module, <code>twitter</code>. I've tried using it to post a regular status which worked, so it's not an authentication problem. In the example on the <code>twitter</code> module's documentation, they do this (raw binary, not base64):</p>
  
  <pre><code>var data = require('fs').readFileSync('image.jpg');
  client.post('media/upload', {media: data}, function(error, media, response) { ... }
  </code></pre>
  
  <p>However, the way I'm doing it, I can't actually read a file -- all I've got is the encoded data from the JSON string. Anyway, here's what I've got:</p>
  
  <pre><code>...
  let data = JSON.parse(req.rawBody).imageb64;
  //console.log(data);
  client.post('media/upload', {media_data: data}, function(error, media, response) {
  
    if (!error) {
      console.log(media);
      var status = {
        status: 'api test',
        media_ids: media.media_id_string
      }
  
      client.post('statuses/update', status, function(error, tweet, response) {
        if (!error) {
          console.log(tweet);
        }
      });
  
    }  else {
      console.log(response)
    }
  });
  </code></pre>
  
  <p>I suspect the problem is because I'm passing in the data rather than the result of <code>readFileSync</code>. Any ideas on how I can do this without using it?</p>