Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bluesealjs/00b886d8e5c42c5173d649d66189455f to your computer and use it in GitHub Desktop.
Save bluesealjs/00b886d8e5c42c5173d649d66189455f to your computer and use it in GitHub Desktop.
create download link for protected resources using blob
You can allocate an arbitrary object in the browser memory (RAM) as a Blob or File Objects,
then you can access it later via an URL string created using URL.createObjectURL.
This URL will serve the stored object as long as there is some reference to it, and then will be grabage collected automatically.
I think it is a good practice to free it explicitly with URL.revokeObjectURL, otherwise it will be allocated for a long time (about a day?).
TIP: Note a difference between Blob and File Objects. Blob is stored in the memory, File on the file system.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management
chrome://blob-internals/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment