Skip to content

Instantly share code, notes, and snippets.

@philipstanislaus
Last active September 9, 2025 11:09
Show Gist options
  • Save philipstanislaus/c7de1f43b52531001412 to your computer and use it in GitHub Desktop.
Save philipstanislaus/c7de1f43b52531001412 to your computer and use it in GitHub Desktop.
JavaScript: Save a blob to disc
var saveBlob = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (blob, fileName) {
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
};
}());
saveBlob(file, 'test.zip');
@jozefchutka
Copy link

jozefchutka commented Sep 9, 2025

URL.createObjectURL(new Blob([blob], {type:"application/octet-stream"}))

prints url into console, once clicked it will prompt system save file dialog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment