Angular2 Http POST pads binary transfer
<p>I'm trying to send raw binary data (a slice of binary file) using a POST with Angular2's Http class. However on the server side the received data is padded, likely due to some client-side JSON conversion. For example 100000 bytes sent from the browser are read on the server as being 121201 bytes. </p>

<p>I can achieve this raw binary transfer and preserve the number of bytes received on the same server using jQuery.ajax:</p>

<pre><code>  $.ajax({
    type: "POST",
    url: "http://localhost:3000/analysis",
    data: blob,
    processData: false,
    contentType: 'application/octet-stream',
    error: function (err) {
      console.log(err);
    },
    success: function (data) {
      // do something heroic
    }
  });
</code></pre>

<p>The file is being read using FileReader API's <code>readAsBinaryString</code>. My suspicion is that I need to do something like in Angular 1 where you'd set the <code>transformRequest</code> to an empty array, so that the bytes aren't coerced to JSON. Here's the Angular2 version I have:</p>

<pre><code>  getAnalysis = (headerBytes: any) =&gt; {
    let header = new Headers();
    header.append("Content-Type", "application/octet-stream");
    this.http.post("http://localhost:3000/analysis", headerBytes, {
        headers: header
    })
        .retry(3)
        // response data, not data being sent
        .map(responseData =&gt; responseData.json())
        .subscribe(
        data =&gt; this.result = data,
        err =&gt; this.logError(err),
        () =&gt; console.log("request complete")
        );

};
</code></pre>

<p>I could just punt and do this in jQuery, but surely there's a way to do this with the new hotness?</p>