I am trying to send raw binary data (a bit of a binary file) using POST with the Angular2 Http class. However, on the server side, the received data is supplemented, probably due to some client side JSON conversions. For example, 100,000 bytes sent from the browser are counted as 121201 bytes on the server.
I can do this raw binary transfer and save the number of bytes received on one server using jQuery.ajax:
$.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) {
}
});
The file is read using the FileReader API readAsBinaryString. My suspicion is that I need to do something like Angular 1, where you set transformRequestto an empty array so that bytes are not bound to JSON. Here's the version of Angular2 I have:
getAnalysis = (headerBytes: any) => {
let header = new Headers();
header.append("Content-Type", "application/octet-stream");
this.http.post("http://localhost:3000/analysis", headerBytes, {
headers: header
})
.retry(3)
.map(responseData => responseData.json())
.subscribe(
data => this.result = data,
err => this.logError(err),
() => console.log("request complete")
);
};
jQuery, , , ?