[英]Javascript/Nodejs Downloading audio file to disk
想下載這個 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);
});
}
知道這很簡單
const path = "....";
try {
const url = "....";
request(url)
.pipe(fs.createWriteStream(path));
} catch...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.