其他分享
首页 > 其他分享> > base64转file;

base64转file;

作者:互联网

 1 //将base64转换为文件,dataurl为base64字符串,filename为文件名(必须带后缀名,如.jpg,.png)
 2             var arr = newBase64.split(','),
 3                 mime = arr[0].match(/:(.*?);/)[1],
 4                 bstr = atob(arr[1]),
 5                 n = bstr.length,
 6                 u8arr = new Uint8Array(n);
 7             while(n--){
 8                 u8arr[n] = bstr.charCodeAt(n);
 9             }
10             var imgObj =  new File([u8arr], "baseImg.jpg", {type:mime});

 

标签:arr,base64,jpg,file,bstr,var,u8arr
来源: https://www.cnblogs.com/Esther-yan/p/16422031.html