Skip to content Skip to sidebar Skip to footer

Corrupted Download In Angularjs App

I am trying to download a file using FileSaver.js, but I get a corrupted file whenever I hit download button. App is backed by a PHP REST service, and using cURL from command line

Solution 1:

I have found the problem. It was me :)

I had to specify responseType: "arraybuffer" for $http then give str directly to Blob.

Fixed code

// Let str be the data received from $http promise
// This code is run in a "then" callback
// Make sure to specify "responseType: "arraybuffer""for $http

var blob = new Blob([str], {type: 'application/octet-stream'});
saveAs(blob, "AFileName");

I was changing responseType in wrong place.

Post a Comment for "Corrupted Download In Angularjs App"