https://juejin.cn/post/6844903763312902151
/**
* base64转blob
* @param {String} code base64个数数据
* @return {undefined}
* @author xxx
*/
base64ToBlob (code) {
let parts = code.split(';base64,');
let contentType = parts[0].split(':')[1];
let raw = window.atob(parts[1]);
let rawLength = raw.length;
let uInt8Array = new Uint8Array(rawLength);
for (let i = 0; i < rawLength; ++i) {
uInt8Array[i] = raw.charCodeAt(i);
}
return new window.Blob([uInt8Array], {type: contentType, name: 'file_' + new Date().getTime() + '.jpg'});
}
let blob = base64ToBlob(dataUrl);
a标签直接下载dataurl的资源在移动端确实不行,已经踩过坑,可以通过URL.createObjectURL(blob),方法转换成url赋值给href就可在移动端实现下载
blob在webviewe里面好像也不能下载
标签:code,base64,uInt8Array,js,raw,let,blob,移动,下载 From: https://www.cnblogs.com/zhanglw456/p/16970519.html