Skip to content

Instantly share code, notes, and snippets.

@supunUOM
Forked from javilobo8/download-file.js
Created October 21, 2021 13:50
Show Gist options
  • Save supunUOM/090ab57cf5ce6e25d061b59b8b4e0134 to your computer and use it in GitHub Desktop.
Save supunUOM/090ab57cf5ce6e25d061b59b8b4e0134 to your computer and use it in GitHub Desktop.
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
link.click();
});
@supunUOM
Copy link
Author

after adding this it will start the download file using file explorer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment