I am able to store a wav file in cloudant database as a multipart. Here is the code :
var doc = {
_id: timestmp.toString(),
name: strName
};
var attach = {
name: strName,
data: fs.readFileSync(input),
content_type: mimeType
};
try {
db_data.multipart.insert(doc, [attach], now.toString(), function (err, result) {
if(err){
console.log('Error inserting to STT data table' + err);
response.sendStatus(200);
}
else {
console.log('Inserted to db');
}
});
When I download the wav file from cloudant database manually, I am able to play the file. I am trying to do the same using Node js code. But the wav file exported to my system is not playing. Here is the code :
db_data.multipart.get(doc._id, function (err, buffer) {
var inputWav = "input.wav";
if (!err) {
fs.writeFileSync(inputWav, Buffer.from(buffer), "audio/wav");
}
});
Can anyone help ? Basically, I am trying to convert the buffer output returned from cloudant database to audio/wav file mimetype. How to do that ?