文件base64 blob file互转
作者:
芸芸众生ing | 来源:发表于
2020-07-09 16:31 被阅读0次 to(file, type, toType) {
return Promise(Response => {
if (type == "base64" && toType == "blob") {
let arr = file.split(",");
let img = window.atob(arr[1]);
let mime = arr[0].match(/:(.*?);/)[1];
let ia = new Uint8Array(img.length);
for (var i = 0; i < img.length; i++) {
ia[i] = img.charCodeAt(i);
}
Response(new Blob([ia], { type: mime }));
}
if (type == "blob" && toType == "file") {
Response(new File([file], Math.floor(Math.random() * 900) + ".jpeg"));
}
if (type == "file" && toType == "base64") {
var reader = new FileReader();
reader.onload = function() {
Response(this.result);
};
reader.readAsDataURL(file);
}
});
},
本文标题:文件base64 blob file互转
本文链接:https://www.haomeiwen.com/subject/xgsscktx.html
网友评论