1👍
✅
You’re seeing this error because a FileReader‘s readAsDataURL takes a Blob as parameter.
You are currently passing it undefined
(check by running console.log(file)
), because img
is a
File (which is a Blob), and it doesn’t have a files
property.
Passing it the file should work:
// ...
reader.readAsDataURL(img)
👤tao
5👍
You can use this function to convert file to base64
const getBase64 = (file) => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
};
Source:stackexchange.com