My goal is to extract a string from an object I am receiving in the response.
const convertFileToBase64 = (file: File): Promise<string> => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file); // Read as Data URL (includes Base64 encoding)
reader.onload = () => {
const base64 = (reader.result as string).split(',')[1];
resolve(base64);
};
reader.onerror = error => reject(error);
});
};
https://i.sstatic.net/MxZD6.png
Even after using split, I'm still getting the object instead of the desired string:
reader.onload = () => {
const base64 = (reader.result as string).split(',')[1];
resolve(base64);
};