title: Posting File Input as FileReader Binary Data through AJAX Post
body: <p>I am trying to post an attachment uploaded to an HTML file input to a web page through a rest API. The API documentation states that the post is a straight binary content as the body of the HTTP request, not a form file upload.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>$('#_testButton').bind('click', function () {
      var file = document.getElementById('_testFile').files[0]
      var reader = new FileReader();
      reader.onload = function () {
          $.ajax({
              url: '/attachmentURL',
              type: 'POST',
              data: reader.result
          })
      }
      reader.readAsBinaryString(file)
  })
  </code></pre>
  
  <p>I need this to work for a number of different mimeTypes, so I didn't declare it in the code above. However, I have tried declaring contentType:'application/msword' for a .doc file and also tried processData:false and contentType:false.</p>
  
  <p>The data is being posted where it should. However, when I open the file, I get a message that says mimeType:application/x-empty with an empty file OR a file with a bunch of binary characters. I've tried .doc files and a pdf files and the result is the same for both.</p>
  
  <p>Does anyone have a clue what I can change to make this work?</p>