Saving binary file from base64 text data by IE, AD

2019-08-28 22:08发布

问题:

I had a problem when try to saving a binary file by IE, ADODB.Stream on client.

Assume the the client's browser has full permission to write file to hard disk.

Here is my client code witten by javascript.:

var base64_encoded_string = "base64 string of a binary file";
var data = window.atob(base64_encoded_string);
var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 1; // text
stream.Open();
stream.Write(data); //Problem in here
stream.SaveToFile("D:\\Whatever.pfx", 2);
stream.Close();

As I marked problem come from writing binary data. I always got error:

"Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another"

Whatever I format or change data variable to array of bytes, blob ...

Please help me how to input data to write binary file in this circumstance.

回答1:

You need to use WriteText

stream.WriteText(data);