let message = await sequlize.models.chat_message.find({ where: { type: 'voice', them: 'video', phone: '17660590622' }, raw: true })
for (let index = 0; index < message.length; index++) {
const element = message[index];
var file_url = message.message;
var DOWNLOAD_DIR = './downloads/';
download_file_httpget(file_url,index);
}
var download_file_httpget = function (file_url,index) {
try {
var DOWNLOAD_DIR = './downloads/';
var options = {
host: url.parse(file_url).host,
port: 80,
path: url.parse(file_url).pathname
};
var file_name = `${index}.mp3`;
var file = fs.createWriteStream(DOWNLOAD_DIR + file_name);
http.get(options, function (res) {
res.on('data', function (data) {
file.write(data);
}).on('end', function () {
file.end();
console.log(file_name + ' downloaded to ' + DOWNLOAD_DIR);
});
});
} catch (error) {
console.log('err***********', error)
}
};
用node的steam模块下载音频文件播放不了,message是一个数组,如果下载单个文件可以播放,这是为什么?
是不是写错了 是var file_url = element.message ?