Last active
March 22, 2022 14:40
-
-
Save cuneydbolukoglu/8ff34655ef3d6f2ebccffbeb68512cd5 to your computer and use it in GitHub Desktop.
Download files with Axios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
axios({ | |
url: `/api/download/${id}/`, | |
method: 'GET', | |
responseType: 'blob', // important | |
}).then((response) => { | |
const url = window.URL.createObjectURL(new Blob([response], { type: response.type })); | |
const link = document.createElement('a'); | |
link.href = url; | |
link.setAttribute('download', fileName); | |
link.target = '_blank' | |
link.click(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment