Created
September 17, 2019 18:57
-
-
Save gthrm/fa04441268b07532697c506953be8014 to your computer and use it in GitHub Desktop.
_imageEncode from arraybuffer binary to Base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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