title: NodeJs send Binary Data with Request
body: <p>I'm trying to upload Image to wordpress using Wordpress rest API.</p>
  
  <p>Everything is working but, proper image is not getting uploaded. However, when i use Curl image is proper. </p>
  
  <pre><code>curl --request POST \
  --url http://localhost/wordpress/wp-json/wp/v2/media/ \
  --header "cache-control: no-cache" \
  --header "content-disposition: attachment; filename=hh.jpg" \
  --header "authorization: Basic token" \
  --header "content-type: image/jpg" \
  --data-binary "@C://Users/as/Desktop/App _Ideas/hh.jpg" \
  </code></pre>
  
  <p>This curl request is working properly. </p>
  
  <p>Now, when i converted request to Nodejs</p>
  
  <pre><code>request({
          url: ' http://localhost/wordpress/wp-json/wp/v2/media/',
          headers: {
            'cache-control': 'no-cache',
            'content-disposition': 'attachment; filename='+filename,
            'content-type' : 'image/jpg',
            'authorization' : 'Basic token'
          },
          encoding: null,
          method: 'POST',
          body: "@C://Users/as/Desktop/App _Ideas/hh.jpg",
          encoding: null
         }, (error, response, body) =&gt; {
              if (error) {
                 res.json({name : error});
              } else {
                res.json(JSON.parse(response.body.toString()));
              }
         });
  </code></pre>
  
  <p>I'm able to receive json response from wordpress as imge uploaded. But, uploaded image is not proper as binary data passed was not proper. </p>
  
  <p>Wordpress uploades folder shows file <code>hh.jpg</code> for size 17 bytes.. On editing with notepad it show <code>@hh.jpg</code> which means string data is saved as hh.jpg not the actual binary data. </p>
  
  <p>Any ideas how to pass binary data properly with Nodejs.</p>