美文网首页
使用 new FileReader 将图片文件流转化成base6

使用 new FileReader 将图片文件流转化成base6

作者: 家有饿犬和聋猫 | 来源:发表于2022-01-06 16:34 被阅读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....
    

    相关文章

      网友评论

          本文标题:使用 new FileReader 将图片文件流转化成base6

          本文链接:https://www.haomeiwen.com/subject/hdlrcrtx.html