'How to convert base 64 to byte Array?
How to convert base64 to byte Array in angular. I am trying it but it doesn't work.
// file upload
handleUpload(event) {
if (event.target.files[0]) {
this.file = event.target.files[0].name;
}
const file = event.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
// console.log(reader.result);
this.base64ToArrayBuffer(reader.result);
};
}
// base64 to byte array
base64ToArrayBuffer(base64) {
var binary_string = window.atob(base64)
var len = binary_string.length;
var bytes = new Uint8Array(len);
for (var i = 0; i < len; i++) {
bytes[i] = binary_string.charCodeAt(i);
}
console.log(bytes.buffer)
this.fileBase64 = bytes.buffer;
return bytes.buffer;
}
I want to fileBase64 variable to be a byte Array but it doesn't work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
