Skip to content

Instantly share code, notes, and snippets.

@javilobo8
Last active April 9, 2024 12:01
Show Gist options
  • Save javilobo8/097c30a233786be52070986d8cdb1743 to your computer and use it in GitHub Desktop.
Save javilobo8/097c30a233786be52070986d8cdb1743 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();
});
@rr-cory-hartford
Copy link

This is great. Thanks

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