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

PREVIOUS NEXT
Code Example
Javascript :: copy text to clipboard jquery 
Javascript :: jquery add event listener to ckeditor 
Javascript :: how to make a discord.js 8 ball command 
Javascript :: click on child prevent click on parent 
Javascript :: deploy create react app pm2 
Javascript :: localstorage setitem javascript 
Javascript :: express js params 
Javascript :: chrome-doesnt-scale-below-x-500px 
Javascript :: regular expression start and end with same character javascript 
Javascript :: javascript object includes 
Javascript :: send form data with file upload using ajax 
Javascript :: Creating new array from old array without impacting old array 
Javascript :: useMutation on success function not being called 
Javascript :: animationframe javascript 
Javascript :: if else jquery click function 
Javascript :: js loop through object 
Javascript :: speed facebook video 
Javascript :: regex validate link 
Javascript :: npx nestjs 
Javascript :: ecampus kgisl, kgcas, kgisl 
Javascript :: how to kill a running node process 
Javascript :: how remove child in jquery 
Javascript :: js get environment variable 
Javascript :: SyntaxError: Cannot use import statement outside a module 
Javascript :: jquery create input hidden 
Javascript :: how to clear innerhtml in javascript 
Javascript :: find vowel & consonants in a string java script 
Javascript :: js date is weekend 
Javascript :: regex to check if string contains special characters javascript 
Javascript :: javascript add alpha to hex 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =