Skip to content

Instantly share code, notes, and snippets.

@gthrm
Created September 17, 2019 18:57
Show Gist options
  • Save gthrm/fa04441268b07532697c506953be8014 to your computer and use it in GitHub Desktop.
Save gthrm/fa04441268b07532697c506953be8014 to your computer and use it in GitHub Desktop.
_imageEncode from arraybuffer binary to Base64
_imageEncode(arrayBuffer, contentType) {
let u8 = new Uint8Array(arrayBuffer)
let b64encoded = btoa([].reduce.call(new Uint8Array(arrayBuffer), function (p, c) { return p + String.fromCharCode(c) }, ''))
let mimetype = contentType || "image/png"
return "data:" + mimetype + ";base64," + b64encoded
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment