ArrayBuffer to base64 encoded string

前端 未结 12 1322
渐次进展
渐次进展 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:11

    function _arrayBufferToBase64(uarr) {
        var strings = [], chunksize = 0xffff;
        var len = uarr.length;
    
        for (var i = 0; i * chunksize < len; i++){
            strings.push(String.fromCharCode.apply(null, uarr.subarray(i * chunksize, (i + 1) * chunksize)));
        }
    
        return strings.join("");
    }
    

    This is better, if you use JSZip for unpack archive from string

提交回复
热议问题