Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

download file axios nodejs

axios.get('https://xxx/my.pdf', {responseType: 'blob'}).then(response => {
    fs.writeFile('/temp/my.pdf', response.data, (err) => {
        if (err) throw err;
        console.log('The file has been saved!');
    });
});
Comment

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();
});
Comment

axios download file from url

API call to Download file
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to add bootstrap to vue js 
Javascript :: convert string to datetime javascript 
Javascript :: how to add 4 business days in javascript 
Javascript :: add formdata to axios request in js 
Javascript :: js exit fullscreen 
Javascript :: how to hide all fo the paragraphs in jquery 
Javascript :: fibonacci recursion javascript 
Javascript :: how to remove first element of array javascript 
Javascript :: vscode jsx html autocomplete 
Javascript :: moment hour minute 
Javascript :: check jquery version on console 
Javascript :: event.preventDefault() in react hook 
Javascript :: js iterate object 
Javascript :: js find object from value in array 
Javascript :: react create root 
Javascript :: regular expression for password 
Javascript :: how to print two arrays side by side in javascript 
Javascript :: prevent browser back button jquery 
Javascript :: datatable set placeholder 
Javascript :: hide element when pressing button angular 
Javascript :: Format number thousands k javascript 
Javascript :: remove special characters javascript 
Javascript :: datatable without pagination 
Javascript :: mock single function from module jest 
Javascript :: unexpected token export type react bottontab navigation 
Javascript :: vue watch deep property 
Javascript :: node readline question 
Javascript :: react native touchableopacity 
Javascript :: get timezone javascript 
Javascript :: redirect to page in javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =