I'd like to download a protected file from my backed - I have to send authorization headers, so I can't link it directly. I have created following Ajax request to download it:
Ember.$.ajax({
url: self.get("file.filepath"),
type: "GET",
beforeSend: function(xhr) {
xhr.setRequestHeader(header, content);
},
processData: false,
success: function (result, a, xhr) {
var blob = new Blob([result], {type: xhr.getResponseHeader("content-type") || ""});
saveAs(blob, self.get("file.filename"));
}
});
Everything works fine when dealing with text files. However when I try to download binary file (image), I get complete nonsence (even the binary string in response printed via console seems fine to me). So I suppose there's a problem in blob construction.
I have tried to use Int8Array, however it didn't helped. What am I doing wrong?