Skip to content

Instantly share code, notes, and snippets.

@alekssamos
Forked from Deliaz/arrayBufferToBase64.js
Created June 5, 2020 06:33
Show Gist options
  • Select an option

  • Save alekssamos/23fc6e4c645f82380ed1fcdd252c144a to your computer and use it in GitHub Desktop.

Select an option

Save alekssamos/23fc6e4c645f82380ed1fcdd252c144a to your computer and use it in GitHub Desktop.
Convert array buffer to base64 string
function arrayBufferToBase64(buffer) {
let binary = '';
let bytes = new Uint8Array(buffer);
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment