Issue
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.
Solution
// file upload
handleUpload(event) {
if (event.target.files[0]) {
this.file = event.target.files[0].name;
}
const reader = new FileReader();
reader.onload = this.handleReaderLoaded.bind(this);
}
base64ToArrayBuffer(readerEvt) {
var binaryString = readerEvt.target.result;
this.base64textString = btoa(binaryString);
}
Answered By - John Doe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.