Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created May 29, 2019 00:16
Show Gist options
  • Save ThaddeusJiang/2f0db9c4322508fc56f7c7804eba70e5 to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/2f0db9c4322508fc56f7c7804eba70e5 to your computer and use it in GitHub Desktop.
Convert Blob to String in JavaScript [cn] 字节转字符串

TL;DR: Use the readAsText() method.

Example

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment