title: Sending binary data in ajax/jquery REST api
body: <p><strong>To everyone who mask this as a duplicate; please see the other answers you are refering to and the links I have provided here. They content type is <code>audio/wav</code> and not <code>stream/octet</code> as mentioned in other answers. Please don't mark questions as duplicates without reading its content</strong></p>
  
  <p>I am trying to send an audio file to a server, so I can get an JSON response back. This is an IBM Service so we have the REST API provided by them. Below is my code in <code>ajax</code></p>
  
  <pre><code>function recognize()
              {
                  $.ajax
                  ({
                      type: "POST",
                      url: "https://stream.watsonplatform.net/speech-to-text/api/v1/recognize",
                      dataType: 'json',
                      username: "xxxx",
                      password: "xxxx",
                      contentType: "audio/wav",
  
  
                      success: function (data){
                          alert(JSON.stringify(data)); 
                      }
                  });
              }
  </code></pre>
  
  <p>Below is the IBM example for the REST call I am going to make - </p>
  
  <pre><code>curl -u "{username}":"{password}" \
  -H "content-type: audio/wav" \
  --data-binary @"/path/to/file.wav" \
  "https://stream.watsonplatform.net/speech-to-text/api/v1/sessions/{session_id}/recognize"
  </code></pre>
  
  <p>The link to the example page and description is - <a href="http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/speech-to-text/api/v1/#recognize" rel="nofollow">http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/speech-to-text/api/v1/#recognize</a></p>
  
  <p>My question is, how Can I send the binary file via Ajax? This is actually a phonegap application. </p>
  
  <p>Here is an interesting question; if I send the URI of the file into <code>data:</code> tag of the REST call it works. If I send the real path it do not. why???</p>