Created
June 19, 2020 11:17
-
-
Save kumarasinghe/b76456c30d8d280145c4f97ae5215a5c to your computer and use it in GitHub Desktop.
JavaScript download a URL as file in browser
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
// CORS policies apply | |
async function download(url, filename){ | |
let res = await fetch(url) | |
let blob = await res.blob() | |
let a = document.createElement("a"); | |
a.href = URL.createObjectURL(blob) | |
a.download = filename; | |
a.click(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment