在Convert.FromBase64String中输入FileReader.readAsDataURL结果返回格式异常 [英] FileReader.readAsDataURL result returning format exception when entered in Convert.FromBase64String
问题描述
我正在使用以下内容将图像转换为base64编码的字符串.在使用javascript的客户端网站上:
I'm using the following to convert an image to a base64 encoded string. On the client website in javascript:
var reader = new FileReader();
reader.onloadend = function () {
data64 = reader.result;
};
reader.readAsDataURL(myFile);
现在,我将此数据传递给服务器,服务器将执行以下操作:
Now I pass this data to the server, which does the following:
var data = Convert.FromBase64String(data64);
但是这会导致格式异常:
However this results in a format exception:
s的格式无效. s包含一个非base-64字符,两个以上的填充字符或这些填充字符中的非空白字符.
The format of s is invalid. s contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters.
我的输入文件是Windows 7上的示例图像之一->我的图片/示例图片/Tulips.jpeg
My input file is one of the sample images found on Windows 7 -> My Pictures/Sample Pictures/Tulips.jpeg
我如何尝试调试导致如此大结果输出的问题的原因?
How can I attempt to debug what is causing the problem for such a large result output?
推荐答案
好吧,我已经通过使用reader.readAsBinaryString
来解决此问题,然后使用btoa
对其进行了转换.
Okay, I have worked around this by using reader.readAsBinaryString
instead and then converting this using btoa
.
在Convert.FromBase64String
这篇关于在Convert.FromBase64String中输入FileReader.readAsDataURL结果返回格式异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!