// img 是base64图片完整字符串
getUrl(img){
let file = this.base64ImgtoFile(img); // 获取文件流
let imgUrl = window.webkitURL.createObjectURL(file) ||
window.URL.createObjectURL(file); // 获取链接
},
// 获取文件流
base64ImgtoFile(dataurl, filename = "file") {
const arr = dataurl.split(",");
const mime = arr[0].match(/:(.*?);/)[1];
const suffix = mime.split("/")[1];
const bstr = atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], `${
filename}.${
suffix}`, {
type: mime,
});
},
【JS】base64转文件流再转blob
猜你喜欢
转载自blog.csdn.net/qq_43585322/article/details/129690461
今日推荐
周排行