title: Can't upload image file using Wordpress REST API (Node JS)
body: <p>I'm building a Node.js app which have to create posts on Wordpress.com using their REST API.</p>
  
  <p>The problem is that Wordpress doesn't accept the image file I'm trying to upload.</p>
  
  <p>This is an error message I've got: </p>
  
  <blockquote>
    <p>File is empty. Please upload something more substantial.</p>
  </blockquote>
  
  <p>I've tried to pass file both as raw <code>Node.js Buffer</code> or as <code>base64</code> string, but the result is the same.</p>
  
  <p><a href="https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/posts/new/" rel="nofollow">Here is the Wordpress documentation for this request</a>.</p>
  
  <p>I have no problems to create a post without images. 
  Also I'm able to create an image post by passing <code>media_urls</code> param. 
  But I fail to upload a local file. So I think the problem is the way I pass raw file data to Wordpress.</p>
  
  <p>Here is how I read file data and make request to Wordpress API (I'm using <a href="https://www.npmjs.com/package/request" rel="nofollow">npm request library</a> for requests).</p>
  
  <pre><code>var localImage = fs.readFileSync('local/path/to/image.jpg');
  var anotherImageHostedElsewhere = 'http://example.com/image.jpg';
  
  var url = `https://public-api.wordpress.com/rest/v1.1/sites/${myBlogId}/posts/new`;
  
  var headers = {
    'Content-Type': 'multipart/form-data',
    'Authorization': 'Bearer ' + myAccessToken
  }
  
  var formData = {
    title: 'Post title',
    content: 'Post body',
    media: [localImage], //this image fails to upload
    media_urls: [anotherImageHostedElsewhere] //this image is attached ok
  }
  
  var requestOptions = {
    url: url,
    headers: headers,
    formData: formData
  }
  
  request.post(requestOptions, function(error, response, body) {
    console.log(JSON.parse(body));
  });
  </code></pre>
  
  <p>By the way, I have no problems to upload the same raw file to another APIs (for example Twitter or Imageshack).</p>
  
  <p>Also I have no problems with another requests to Wordpress API.</p>
  
  <p>Really appreciate your help.</p>