Skip to main content
added 89 characters in body
Source Link
Jason C
  • 39.8k
  • 14
  • 132
  • 189

Maybe I'm missing something but

let encoded = btoa(await myblob.text().then(btoa);

... is all you need to do to encode a Blob's data to base64. See Blob.text() and btoa().

Or if you want the whole thing as a promise:

let encode = myblob.text().then(btoa);

PS: To decode back to a Blob: new Blob([atob(encoded)])

Maybe I'm missing something but

let encoded = await myblob.text().then(btoa);

... is all you need to do to encode a Blob's data to base64. See Blob.text() and btoa().

PS: To decode back to a Blob: new Blob([atob(encoded)])

Maybe I'm missing something but

let encoded = btoa(await myblob.text());

... is all you need to do to encode a Blob's data to base64. See Blob.text() and btoa().

Or if you want the whole thing as a promise:

let encode = myblob.text().then(btoa);

PS: To decode back to a Blob: new Blob([atob(encoded)])

Source Link
Jason C
  • 39.8k
  • 14
  • 132
  • 189

Maybe I'm missing something but

let encoded = await myblob.text().then(btoa);

... is all you need to do to encode a Blob's data to base64. See Blob.text() and btoa().

PS: To decode back to a Blob: new Blob([atob(encoded)])