功能:将base64图片字符串转换为 File 对象 参数说明: dataurl base64图片字符串 filename:自定义文件名称
export const base64ToFile = (dataurl, filename="test") => {
let arr = dataurl.split(','), mine = arr[0].match(/:(.*?);/)[1], bstr =atob(arr[1]), n = bstr.length, u8arr =new Uint8Array(n), suffix = mine.split("/")[1];
while(n--){
u8arr[n] = bstr.charCodeAt(n);
}
let theBlob = new Blob([u8arr], {type: mine})
theBlob.lastModifiedDate = new Date()
theBlob.name = `${filename}.jpg`
console.log(theBlob)
return theBlob
}
最后修改于 2021-03-24 10:34:50
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

