Last active
October 6, 2025 06:46
-
-
Save philipstanislaus/c7de1f43b52531001412 to your computer and use it in GitHub Desktop.
JavaScript: Save a blob to disc
This file contains hidden or 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'); |
Is there any difference between revoking the blob url through the window URL instance like this:
window.URL.revokeObjectURL(fileUrl)
and removing it by calling the static method directly?:
URL.revokeObjectURL(fileUrl)
Author
Is there any difference between revoking the blob url through the window URL instance like this:
window.URL.revokeObjectURL(fileUrl)and removing it by calling the static method directly?:URL.revokeObjectURL(fileUrl)
It's too long ago that I looked into this, but IIRC, there was a difference between testing/CI environments and the browser.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
prints url into console, once clicked it will prompt system save file dialog