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)
})
FileReader is part of Web API in a browser but not in Node.js Try to use native Node.js method to read from a file or try to search an appropriate npm package
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.