Last active
March 19, 2023 15:18
-
-
Save gryphon2411/0517140511a1ee77e4a641a48a157a36 to your computer and use it in GitHub Desktop.
Download file without blob
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
/** | |
* 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