ArrayBuffer转为base64
时间: 2023-07-06 21:09:06 浏览: 149
Javascript base64编码实现代码
可以使用以下代码将 ArrayBuffer 转换为 base64 编码:
```javascript
function arrayBufferToBase64(buffer) {
let binary = '';
const bytes = new Uint8Array(buffer);
const len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
```
使用示例:
```javascript
const myArrayBuffer = new ArrayBuffer(8);
const base64String = arrayBufferToBase64(myArrayBuffer);
console.log(base64String);
```
阅读全文