johnpaulada
3/27/2017 - 3:09 AM

Blob to String conversion example in JavaScript using the FileReader API. This displays "Lorem ipsum sit" in the console.

Blob to String conversion example in JavaScript using the FileReader API. This displays "Lorem ipsum sit" in the console.

const blb    = new Blob(["Lorem ipsum sit"], {type: "text/plain"});
const reader = new FileReader();

// This fires after the blob has been read/loaded.
reader.addEventListener('loadend', (e) => {
  const text = e.srcElement.result;
  console.log(text);
});

// Start reading the blob as text.
reader.readAsText(blb);