I've got a POST request like this:
$scope.myFunction = function (name, id, value) {
$http.post(/retrievePDFFiles, {
name: name,
id: id,
value: value
}).success(function(data, headers) {
var filename = headers('filename');
if(data.byteLength > 250) {
var blob = new Blob([data], {type : 'application/pdf;charset=utf-8'});
saveAs(blob, filename);
} else {
console.log("Error");
}
}).error(function(data) {
console.log(data);
});
}
With this call i send some parameters to save them in a table in my db and as response i have a pdf stream. The request to the server it returns correctly 200 and all parameters are corrected and everything is saved in db but the pdf not works. I've got an error in console:
SyntaxError: Unexpected token %
and if i debug the request it goes in the .error function. I think the problem is that it doesn't recognize that it needs to download a stream and, i don't know, it doesn't work. I think just adding
responseType : 'arraybuffer'
somewhere it will works but i don't know where! I can't touch the structure of the parameters.. Any idea?
EDIT: i tried as written here with no results How to read binary data in AngularJS in an ArrayBuffer?