Skip to content

Instantly share code, notes, and snippets.

@ducdhm
Created October 4, 2019 05:45
Show Gist options
  • Save ducdhm/b24d1cc78fe9a4a8f765031ef8ab864e to your computer and use it in GitHub Desktop.
Save ducdhm/b24d1cc78fe9a4a8f765031ef8ab864e to your computer and use it in GitHub Desktop.
Download file from url
function downloadFile(url, filename) {
fetch(url)
.then(resp => resp.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment