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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.