Search code examples
javascriptfetchfilereader

FileReader - fetch image and converti into base64


I'm trying to fetch and convert into blob/base64 an image from an online resource but the code I'm using seems not working

fetch('https://example.com/image.jpg')
.then( res => res.blob() )
.then( data => {
    const reader = new FileReader()
    reader.onloaded = () => {
      console.log(reader.readAsDataURL(data))    
    }     
})

what's wrong with it and what I need to change to fix it?


Solution

  • See Convert blob to base64

    This issue was solved already ;)