Saving binary file from base64 text data by IE, ADODB.Stream to hard disk

橙三吉。 提交于 2019-12-11 16:23:46

问题


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); 


来源:https://stackoverflow.com/questions/25055323/saving-binary-file-from-base64-text-data-by-ie-adodb-stream-to-hard-disk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!