How to POST binary data in request using request library?
<p>I have to send binary contents of a remote file to an API endpoint. I read the binary contents of remote file using <a href="https://www.npmjs.com/package/request" rel="noreferrer">request library</a> and store it in a variable. Now with contents in the variable ready to be sent, how do I post it to remote api using request library.</p>

<p>What I have currently and doesn't work is:</p>

<pre><code>const makeWitSpeechRequest = (audioBinary) =&gt; {
  request({
    url: 'https://api.wit.ai/speech?v=20160526',
    method: 'POST',
    body: audioBinary,
  }, (error, response, body) =&gt; {
    if (error) {
      console.log('Error sending message: ', error)
    } else {
      console.log('Response: ', response.body)
    }
  })
}
</code></pre>

<p>We can safely assume here that <code>audioBinary</code> has binary contents that were read from a remote file.</p>

<p><strong>What do I mean when I say it doesn't work?</strong><br>
The payload shows up different in request debugging.
Actual binary payload: <code>ID3TXXXmajor_brandisomTXXXminor_version512TXXX</code><br>
Payload showed in debugging: <code>ID3\u0004\u0000\u0000\u0000\u0000\u0001\u0006TXXX\u0000\u0000\u0000\</code></p>

<p><strong>What works in Terminal?</strong><br>
What I know works from Terminal is with a difference that it reads the contents of file too in the same command:</p>

<pre><code>curl -XPOST 'https://api.wit.ai/speech?v=20160526' \
      -i -L \
      --data-binary "@hello.mp3"
</code></pre>