I am trying to convert my uploaded image to a base64 before sending it to the backend for processing, and I am using readAsDataUrl
for doing the same, but the result comes as null always,
convertToBase64 () --
const convertFileToBase64 = file => new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file.rawFile);
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
});
Blob :
{
"rawFile": {
"path": "Logo.png"
},
"src": "blob:http://localhost:3000/5ff2faa0-6f37-4c2e-906a-4c953d146efa",
"title": "Logo.png"
}
I am passing this blob as a file parameter to my convertToBase64
method, but reader.result
is null always
While debugging I can see the promise being still pending and not resolved, could this be the reason it being null? How do I fix this?