赞
踩
let reader = new FileReader();
reader.readAsDataURL(file[0])
console.log(reader)
base64ToBlob(urlData) {
let arr = urlData.split(",");
let mime = arr[0].match(/:(.*?);/)[1];
let bstr = atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
}
base64toFile(dataurl, fileName) {
let arr = dataurl.split(",");
// let mime = arr[0].match(/:(.*?);/)[1];
let bstr = atob(arr[1]);
let n = bstr.length;
let u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], fileName);
}
BlobToBlobURL(BlobFile,type) {
let blob = new Blob([BlobFile], { type : type });// 图片:"image/jpeg"
const blobUrl = URL.createObjectURL(blob);
return blobUrl ;
}
blobToArrayBuffer(){
let blob = new Blob([1,2,3,4])
let reader = new FileReader();
reader.onload = function(result) {
console.log(result);
}
reader.readAsArrayBuffer(blob);
}
let blob = new Blob([buffer])
urlToBlobBase64(imgUrl) {
return new Promise((resolve) => {
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
xhr.open("get", imgUrl, true);
xhr.responseType = "blob";
xhr.onload = function () {
if (this.status == 200) {
var blob = this.response;
let oFileReader = new FileReader();
oFileReader.onloadend = function (e) {
resolve({ blob, base64: e.target.result });
};
oFileReader.readAsDataURL(blob);
} else {
reject(new Error("异常"));
}
};
xhr.send();
xhr.onerror = () => {
reject(new Error("异常"));
};
});
}
function blobToDataURI(blob,callback) {
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = function (e) {
callback(e.target.result);
};
}
// 调用
blobToDataURI(blobData, function (result) {
console.log(result);
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。