Save Binary File to Disk in JavaScript
...I am consuming an XML web service using javascript..
One of the elements is a base64 encoded byte array... so it is a binary array of a document
from my webserver...
I REALLY need to know how I can from the client write this file to disk on my client using
javascript... I dont mind if I have to use ActiveXObjects.
An answer ...
1. Decode the base64-encoded data into a string using my [Link] or similar.
2. Create a [Link] object, configure it for Text Mode (2) and the ISO-8859-1
Charset.
3. Finally just call WriteText() followed by SaveToFile() and Close().
Warning: This will only work on Windows machines running Internet Explorer (or another
ActiveX-capable web browser). It will also be suppressed unless the website it is running
from is set as Trusted or the user specifically allows the actions.
Example ...
var data = DecB64(base64_encoded_string);
var stream = new ActiveXObject("[Link]");
[Link] = 2; // text
[Link] = "ISO-8859-1";
[Link]();
[Link](data);
[Link]("C:\\[Link]", 2);
[Link]();
References ...
MSDN: ADO SaveToStream