node.js axios download file stream and writeFile

前端 未结 8 1001
花落未央
花落未央 2020-12-24 08:50

i want download a pdf file with axios and save on disk (server side) with fs.writeFile, i have tried:

axios.get(\'https://xxx/my.pd         


        
8条回答
  •  情深已故
    2020-12-24 09:12

    You can simply use response.data.pipe and fs.createWriteStream to pipe response to file

    axios({
        method: "get",
        url: "https://xxx/my.pdf",
        responseType: "stream"
    }).then(function (response) {
        response.data.pipe(fs.createWriteStream("/temp/my.pdf"));
    });
    

提交回复
热议问题