Skip to content

Instantly share code, notes, and snippets.

@MaxWright
Forked from robnyman/xhr-BlobBuilder.js
Created August 23, 2018 21:37
Show Gist options
  • Save MaxWright/708c57895c447615c34dbb2086a34dc1 to your computer and use it in GitHub Desktop.
Save MaxWright/708c57895c447615c34dbb2086a34dc1 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