使用 new FileReader 将图片文件流转化成base6
2022-01-06 本文已影响0人
家有饿犬和聋猫
// blob = 文件流
const blobToDataURL = (blob) => {
return new Promise((resolve, reject) => {
let reader = new FileReader();
reader.addEventListener('load', () => {
resolve(reader.result); // reader.result即为包含文件内容的字符串
});
reader.readAsDataURL(blob);
});
};
返回base64编码
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCBOyBDgDASIAAhEBAxEB/8QAHwAAAQQDAQEBAQAAAAAAAAAAAAUGBwgDBAkCAQoL/8QAhBAAAQMCBAMFBQUGAwUBAAFFAQIDEQQhAAUSMQZBUQcTImFxFDKBkaEII7HB8AkVQtHh8RYzUgoXGCRictMlQ1aCphkaJig0NjhFU4WS1zVGVViiqLLExSc3REhjZGhzhJSVl7PC0kd1eIaIk9QpV....