Closed leoteixeira2016 closed 3 years ago
client.on('message', async msg => {
if(msg.type == 'image' && msg.hasMedia) {
const image = await msg.downloadMedia();
let from = msg.from.split("@", 1);
var base64DataSp = image.data.split(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
fs.writeFile('/var/www/html/'+from+msg.timestamp+'.jpg', base64DataSp,{encoding: 'base64'}, function(err){
if(err){
console.log(image);
console.log('The file has been Faild!');
}else{
console.log('The file has been saved!');
}
});
}
});
for image download
I usually receive messages but how to treat to receive images and audios? Any idea?