how to download files using axios

Solutions on MaxInterview for how to download files using axios by the best coders in the world

showing results for - "how to download files using axios"
Enrico
24 May 2020
1axios({
2    url: 'http://api.dev/file-download', //your url
3    method: 'GET',
4    responseType: 'blob', // important
5}).then((response) => {
6    const url = window.URL.createObjectURL(new Blob([response.data]));
7    const link = document.createElement('a');
8    link.href = url;
9    link.setAttribute('download', 'file.pdf'); //or any other extension
10    document.body.appendChild(link);
11    link.click();
12});
13