简体   繁体   中英

Javascript/Nodejs Downloading audio file to disk

Looking to download this wav file. Response.pipe(fileStrm) isn't doing it for me. Ive looked around. Wondering what the standard way of downloading media from a URL to file is these days.

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

}

Knew it was simple

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

    } catch...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM