JSFiddle - React, Tailwind, and code Playground
by kwikwag
JavaScript
function downloadUrlAsBlob(url, cb) {
// Create XHR
var xhr = new XMLHttpRequest(),
blob;
xhr.open("GET", url, true);
// Set the responseType to blob
xhr.responseType = "blob";
xhr.addEventListener("load", function () {
console.log("##load ",xhr.status);
if (xhr.status === 200) {
console.log("##",url," retrieved");
// File as response
blob = xhr.response;
// Put the received blob into IndexedDB
cb(blob);
}
}, false);
// Send XHR
xhr.send();
}