Save to Local File from Blob

Your best option is to use a blob url (which is a special url that points to an object in the browser’s memory) :

var myBlob = ...;
var blobUrl = URL.createObjectURL(myBlob);

Now you have the choice to simply redirect to this url (window.location.replace(blobUrl)), or to create a link to it. The second solution allows you to specify a default file name :

var link = document.createElement("a"); // Or maybe get it from the current document
link.href = blobUrl;
link.download = "aDefaultFileName.txt";
link.innerHTML = "Click here to download the file";
document.body.appendChild(link); // Or append it whereever you want

Leave a Comment