Skip to content

Instantly share code, notes, and snippets.

@gryphon2411
Last active March 19, 2023 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gryphon2411/0517140511a1ee77e4a641a48a157a36 to your computer and use it in GitHub Desktop.
Save gryphon2411/0517140511a1ee77e4a641a48a157a36 to your computer and use it in GitHub Desktop.
Download file without blob
/**
* Downloads a file from a given URL.
**/
function download(url) {
return new Promise((resolve, reject) => {
// Workaround for a programmatical file download.
const anchor = document.createElement("a");
anchor.href = url;
anchor.setAttribute("download", "");
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
console.log("FILE DOWNLOAD: " + url);
resolve();
});
}
// Example for usage
download("https://www.kernel.org/pub/software/scm/git/git-2.40.0.tar.gz");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment