Last active
February 12, 2025 13:46
-
-
Save philipstanislaus/c7de1f43b52531001412 to your computer and use it in GitHub Desktop.
JavaScript: Save a blob to disc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
life saver!
thanks a bunch!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ChrisRoald, if you need to deal with data streams that are on the order of client RAM, you should *not* be creating
Blob
s that store the entire data stream in the first place, as they are inherently in-RAM objects.Instead you should use
showSaveFilePicker
/FileSystemWritableFileStream
— or for Firefox this ServiceWorker-based polyfill, pending proper support.