Saving Blob to a file
- Create an url from a
Blob
usingcreateObjectUrl
. - Create an element with tag
a
and use the url generated above. Set properties such asa.download
anda.href
on thisa
. Usea.click
to click on thisa
.
Here is the function.
saveBlob : function(blob, filename) {
var url = window.URL.createObjectURL(blob);
var a = document.createElement("a");
a.target = "_blank";
a.href = url;
a.download = filename;
a.onclick = function(e) {
setTimeout( () => {
window.URL.revokeObjectURL(url);
}, 100);
};
a.click();
a.remove();
},