I am calling a javascript function to initialize a variable value in Oracle Visual Builder (VBCS). The function takes the binary data as input and needs to return Base64 converted string synchronously so that the Base64 converted string is assigned to the VBCS variable.
The function does not return the Base64 converted string. How do I make it return the Base64 string to the calling function?
PageModule.prototype.convertbase64 = function (data) {
const blob = new Blob([data], {
type: "application/octet-stream"
});
function blobToBase64(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => resolve(reader.result.toString().substr(reader.result.toString().indexOf(',') + 1));
reader.onerror = error => reject(error);
console.log(new Date());
});
};
const retstring = blobToBase64(blob).then(finalString => { return finalString });
console.log('retstring value', retstring);
return retstring;
};