Skip to content

Instantly share code, notes, and snippets.

@examinedliving
Created July 23, 2020 17:20
Show Gist options
  • Save examinedliving/67af74ba3263fd6567af8a7b9bce226a to your computer and use it in GitHub Desktop.
Save examinedliving/67af74ba3263fd6567af8a7b9bce226a to your computer and use it in GitHub Desktop.
Download Excel file with axios
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