Skip to content

Instantly share code, notes, and snippets.

@piotrwitek
Last active May 27, 2019 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save piotrwitek/a311b6b665d4416d030ff81fa1d53975 to your computer and use it in GitHub Desktop.
Save piotrwitek/a311b6b665d4416d030ff81fa1d53975 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