0% found this document useful (0 votes)
166 views1 page

Save Binary File To Disk in JavaScript

The document discusses how to save a binary file to disk in JavaScript by decoding a base64-encoded byte array from a web service into a string, creating an ADODB.Stream object to write the string to disk as a file, and providing an example using ActiveXObjects to do so on Windows machines using Internet Explorer.

Uploaded by

Kosta Nikolic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views1 page

Save Binary File To Disk in JavaScript

The document discusses how to save a binary file to disk in JavaScript by decoding a base64-encoded byte array from a web service into a string, creating an ADODB.Stream object to write the string to disk as a file, and providing an example using ActiveXObjects to do so on Windows machines using Internet Explorer.

Uploaded by

Kosta Nikolic
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

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 base64.js or similar.
2. Create a ADODB.Stream 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("ADODB.Stream");
stream.Type = 2; // text
stream.Charset = "ISO-8859-1";
stream.Open();
stream.WriteText(data);
stream.SaveToFile("C:\\Whatever.dat", 2);
stream.Close();

References ...
MSDN: ADO SaveToStream

You might also like