Skip to content

Instantly share code, notes, and snippets.

@khoahuynhdev
Last active May 25, 2019 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khoahuynhdev/a6bd78273bc9950abb9aab4c91587395 to your computer and use it in GitHub Desktop.
Save khoahuynhdev/a6bd78273bc9950abb9aab4c91587395 to your computer and use it in GitHub Desktop.
download file with 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();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment