Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript:从文件读取器中提取base64字符串_Javascript - Fatal编程技术网

JavaScript:从文件读取器中提取base64字符串

JavaScript:从文件读取器中提取base64字符串,javascript,Javascript,我在客户端(javascript)中有一个blob图像,我想将其转换为base64字符串。然后,将其传递给代码隐藏(C#) 我使用以下代码将blob转换为base64字符串: var reader = new FileReader(); reader.onload = function (event) { createImage(event.target.result); //event.target.results co

我在客户端(javascript)中有一个blob图像,我想将其转换为base64字符串。然后,将其传递给代码隐藏(C#)

我使用以下代码将blob转换为base64字符串:

 var reader = new FileReader();
                reader.onload = function (event) {
                    createImage(event.target.result); //event.target.results contains the base64 code to create the image.
                };
                reader.readAsDataURL(blob);//Convert the blob from clipboard to base64
我试图显示reader对象以查看base64字符串的外观。我得到了这个
[objectfilereader]


我想从中提取base64字符串,如何做???

在javascript中编码/解码base64的简单方法:

var str=“要编码的一些示例js”;
函数utoa(str){
返回窗口.btoa(unescape(encodeURIComponent(str));
}
控制台日志(“编码:+utoa(str));
函数atou(str){
返回解码组件(escape(window.atob(str));
}

日志(“解码:+atou(utoa(str)))我认为当您提到javascript转换为base64时,这对您很有用。当您想要解码为c#base64时,这一信息也很有用