Skip to content

Instantly share code, notes, and snippets.

@robnyman
Created February 23, 2012 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robnyman/1893530 to your computer and use it in GitHub Desktop.
Save robnyman/1893530 to your computer and use it in GitHub Desktop.
xhr-BlobBuilder
// Create XHR
var xhr = new XMLHttpRequest(),
blob;
xhr.open("GET", "elephant.png", true);
// Set the responseType to blob
xhr.responseType = "blob";
xhr.addEventListener("load", function () {
if (xhr.status === 200) {
console.log("Image retrieved");
// File as response
blob = xhr.response;
// Put the received blob into IndexedDB
putElephantInDb(blob);
}
}, false);
// Send XHR
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment