Skip to content

Instantly share code, notes, and snippets.

@dracon
Forked from Tomassito/download-file.js
Created June 27, 2018 14:06
Show Gist options
  • Save dracon/8598e7db93912f1bef7a4c6b91e97eb9 to your computer and use it in GitHub Desktop.
Save dracon/8598e7db93912f1bef7a4c6b91e97eb9 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');
link.click();
window.URL.revokeObjectURL(url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment