Answers for "How to download files using axios"

1

How to download files using axios

axios({
    url: 'http://api.dev/file-download', //your url
    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'); //or any other extension
    document.body.appendChild(link);
    link.click();
});
Posted by: Guest on September-18-2021

Code answers related to "How to download files using axios"

Code answers related to "Javascript"

Browse Popular Code Answers by Language