In my typescript application, I am utilizing the FileReader
to convert a blob into a base64 image for display within the template.
adaptResultToBase64(res: Blob): string {
let imageToDisplay : string | ArrayBuffer | null = '';
const reader = new FileReader();
reader.onloadend = function () {
imageToDisplay = reader.result;
return imageToDisplay;
};
reader.readAsDataURL(res);
return imageToDisplay;
}
Even though the base64 string is correctly displayed inside the read.onloadend
function, I encounter difficulty passing it out of the function scope.
I attempted using a callback but encountered issues where it returned an empty string when called elsewhere.