I am trying to save a binary string to file using Filesaver.js. I am specifying the charset as ANSI but the file has the UTF-8 encoding.
var blob = new Blob([bin], {type: "octet/stream;charset=ANSI"});
saveAs(blob, "binfile.dat");
Is there a way to save the file as ANSI?
Are you sure bin is ANSI data? I had the same problem where I wanted to download a zip file from the server. It turns out that I had to specify in the header of my request what response I wanted. Here's my code sample in Angular downloading a zip file but it will be the same concept no matter how you make your http request:
$http.get(url, { responseType: 'arraybuffer' })
Then you can create the Blob and save it:
var blob = new Blob([bin], { type: "application/zip", responseType: 'arraybuffer' });
saveAs(blob, "binfile.zip");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With