Skip to content

Instantly share code, notes, and snippets.

@1c7
Last active January 28, 2020 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1c7/091ae01b9182cd4db06aef692308a5ff to your computer and use it in GitHub Desktop.
Save 1c7/091ae01b9182cd4db06aef692308a5ff to your computer and use it in GitHub Desktop.
Read blob URL content
// Read blob url like this one:
// blob:http://localhost:8080/611963a8-1e5a-4de3-9fa2-3fa39a82a2a2
// This blob url come from URL.createObjectURL(File);
function turn_blob_to_file(blob_url) {
var xhr = new XMLHttpRequest();
xhr.responseType = "blob";
xhr.onload = function() {
var blob = xhr.response;
var file = new File([blob], "a.ass", { type: "plain/text" });
//
// Done. write more code here. For example:
//
var reader = new FileReader();
reader.onload = function() {
var text = reader.result;
console.log(text);
};
reader.readAsText(file, "UTF-8");
};
xhr.open("GET", blob_url);
xhr.send();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment