javascript fetch an image and create base64


I’m using CloudFlare service workers and I want to fetch an image and then generate a base64 representation of it.

So something like this:

const res = await fetch('https://cdn.cnn.com/cnnnext/dam/assets/211010073527-tyson-fury-exlarge-169.jpg')
  const blob = await res.blob();
  
  console.log(blob)
  console.log(btoa(blob))

this of course doesn’t work, any ideas how to get this resolved?

Source: JavaSript – Stack Overflow

October 13, 2021
Category : News
Tags: base64 | cloudflare | javascript | service-worker

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.