//base64格式转文件流
function baseTofile(base64) {
var bytes = window.atob(base64.split(",")[1]); //去掉url的头,并转换为byte
//处理异常,将ascii码小于0的转换为大于0
var ab = new ArrayBuffer(bytes.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
return new Blob([ab], { type: "image/png" });
}
function blobtoFile({ type } = blob) {
console.log(type, "type");
return new File([blob], "图片文件", { type });
}
//生成file文件
blobtoFile(blob)
base64转file
最新推荐文章于 2023-11-12 09:25:57 发布