0

想下载这个 wav 文件。Response.pipe(fileStrm) 不是为我做的。我环顾四周。想知道这些天从 URL 下载媒体到文件的标准方法是什么。

const request = require('request').defaults({rejectUnauthorized:false});
const url = "https://..../00015.wav";
const path ="./data/my.wav";

async function getVideo22(url,path){
    var options = { 
    'method': 'GET',
     'url': url,
     'headers': {
     }
   };
   var fileStrm = fs.createWriteStream(path);

   request(options, function (error, response) {
        if (error) throw new Error(error);
       //need to write file to disk
        
       response.pipe(fileStrm);
});

}
4

1 回答 1

0

知道这很简单

 const path = "....";
 try {
       const url = "....";
       request(url)
       .pipe(fs.createWriteStream(path));

    } catch...
于 2021-03-05T09:46:09.803 回答