Last active
January 28, 2020 03:18
-
-
Save 1c7/091ae01b9182cd4db06aef692308a5ff to your computer and use it in GitHub Desktop.
Read blob URL content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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