function base64ToUint8Array(base64String) {
const BASE64_MARKER = ';base64,';
const base64Index = base64String.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
const base64 = base64String.substring(base64Index);
let rawData = Base64.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
console.log('outputArray',outputArray.length)
return outputArray.buffer;
}
let aa = 'data:application/dat;base64,EooBCkQIARJACAgQNBoCrwEgACgAMAA4lNwHQiQIAxIgyCazJ1eoSewjpJyWH675MT5aICOnZ8A1y04eULg5XHRIAFIECAESABAAGkCJEmStGfFunnIh94pH/peMTIbrLoluZpVCCw0JQLe+tSOsDYxLJ1u1OnLF/4ZosFDt+H6TKNTOfj3gu0cSAA2a';
let arrayBuffer = base64ToUint8Array(aa);
let arr = Array.prototype.slice.call(new Uint8Array(arrayBuffer ));
console.log('arrarrarrarr',arr.toString() )
在安卓中的到的是 数组[18,253,1,10,68,8,1,18,64,8,8,16,52,26,2,253,1,32,0,40,0,48,0,56,253,253,7,66,36,8,3,18,32,253,38,253,39,87,253,73,253,35,253,253,253,31,253,253,49,62,90,32,35,253,103,253,53,253,78,30,80,253,57,92,116,72,0,82,4,8,1,18,0,16,0,26,64,253,18,100,253,25,253,110,253,114,33,253,253,71,253,253,253,76,253,253,46,253,110,102,253,66,11,13,9,64,253,253,253,35,253,13,253,75,39,91,253,58,114,253,253,253,104,253,80,253,253,126,253,40,253,253,126,61,253,71,18,0,13,253]
在ios中的到的 [ 18,138,1,10,68,8,1,18,64,8,8,16,52,26,2,175,1,32,0,40,0,48,0,56,148,220,7,66,36,8,3,18,32,200,38,179,39,87,168,73,236,35,164,156,150,31,174,249,49,62,90,32,35,167,103,192,53,203,78,30,80,184,57,92,116,72,0,82,4,8,1,18,0,16,0,26,64,137,18,100,173,25,241,110,158,114,33,247,138,71,254,151,140,76,134,235,46,137,110,102,149,66,11,13,9,64,183,190,181,35,172,13,140,75,39,91,181,58,114,197,255,134,104,176,80,237,248,126,147,40,212,206,126,61,224,187,71,18,0,13,154]
经测试 ios中的值为正确的值
在浏览器中也是ios的值
4 个回复
DCloud_Android_DQQ
好,我试试
DCloud_Android_DQQ
这里的Base64 哪里来的。
3***@qq.com (作者)
不好意思 这个是定义了个变量 引用了个模块 直接用atob就行了
2021-01-18 17:10
DCloud_Android_DQQ
回复 3***@qq.com: 好
2021-01-18 17:38
3***@qq.com (作者)
回复 DCloud_Android_DQQ: 有结果吗?
2021-01-20 18:09
DCloud_Android_DQQ
回复 3***@qq.com: 我看看
2021-01-20 18:22
DCloud_Android_DQQ
我这里测试没有复现问题
Android: 荣耀30
IOS: iPhone 7P
对比:
测试代码:
3***@qq.com (作者)
我试了下 还是不对 现在不用这个了 换了种方式 用了个模块 暂时可以用了
2021-01-21 11:51
3***@qq.com (作者)
我这又试了下 还是不对 手机是华为nova 6 se