Created
July 23, 2020 17:20
-
-
Save examinedliving/67af74ba3263fd6567af8a7b9bce226a to your computer and use it in GitHub Desktop.
Download Excel file 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
export function someFunction(values) { | |
return (dispatch) => { | |
... | |
const method = 'GET'; | |
const url = 'http://go.api/download_file'; | |
... | |
axios | |
.request({ | |
url, | |
method, | |
responseType: 'blob', //important | |
}) | |
.then(({ data }) => { | |
const downloadUrl = window.URL.createObjectURL(new Blob([data])); | |
const link = document.createElement('a'); | |
link.href = downloadUrl; | |
link.setAttribute('download', 'file.zip'); //any other extension | |
document.body.appendChild(link); | |
link.click(); | |
link.remove(); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment