个人资料

跳过导航链接首页 > 博客列表 > 博客正文

Js将blob转换为base64

:

-函数

        async function blobToBase64(blob) {
            let buffer = await blob.arrayBuffer()
            let bytes = new Uint8Array(buffer);
           
            // do anything with the byte array here
            let binary = ''
            var len = bytes.byteLength;
            for (var i = 0; i < len; i++) {
                binary += String.fromCharCode(bytes[i]);
            }
            base64 = 'data:image/webp;base64,' + window.btoa(binary)
            //
            return base64
        }

-使用

  blobToBase64(blobInfo.blob()).then(base64 => {

      console.log(base64);

      });

  });

songshizhao
最初发表2025/6/7 11:07:02 最近更新2025/6/7 11:07:02 15
为此篇作品打分
10