6

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?

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I had an issue with the encoding. The file downloaded was always encoded as UTF-8, messing up with it. It solved the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.