I am trying to convert my image to base64. So I create this function for this. But the problem is when I try to run my program I have an error called ReferenceError: FileReader is not defined. I have no idea what is this error about.
This is my code..?
const toDataURL = url => fetch(url)
.then(response => response.blob())
.then(blob => new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result)
reader.onerror = reject
reader.readAsDataURL(blob)
}).catch((error) => {
console.log(error);
});
)
toDataURL('https://www.gravatar.com/avatar/d50c83cc0c6523b4d3f6085295c953e0')
.then(dataUrl => {
console.log('RESULT:', dataUrl)
})