ArrayBuffer to base64 encoded string

前端 未结 12 1321
渐次进展
渐次进展 2020-11-22 07:16

I need an efficient (read native) way to convert an ArrayBuffer to a base64 string which needs to be used on a multipart post.

12条回答
  •  心在旅途
    2020-11-22 08:20

    For those who like it short, here's an other one using Array.reduce which will not cause stack overflow:

    var base64 = btoa(
      new Uint8Array(arrayBuffer)
        .reduce((data, byte) => data + String.fromCharCode(byte), '')
    );
    

提交回复
热议问题