“Как загрузить файлы с помощью Axios” Ответ

Скачать файл 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!');
    });
});
DevLorenz02

Как загрузить файлы с помощью 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();
});
anonimus_desu

Ответы похожие на “Как загрузить файлы с помощью Axios”

Вопросы похожие на “Как загрузить файлы с помощью Axios”

Больше похожих ответов на “Как загрузить файлы с помощью Axios” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования