How to download a multipart wav file from cloudant database and save locally using Node JS and REST API?
Clash Royale CLAN TAG#URR8PPP
How to download a multipart wav file from cloudant database and save locally using Node JS and REST API?
I am stuck in retrieving multipart from cloudant using Node JS API. Hence, I used REST API to download the wav file from cloudant database. But its not downloading wav file from https URL. When I enter the https URL directly in browser, it prompts me to save file locally. So, the URL is correct.
var request1 = require('request');
var filestream = fs.createWriteStream("input.wav");
var authenticationHeader = "Basic " + new Buffer(user + ":" + pass).toString("base64");
request1( url : "example.com/data/1533979044129/female";, headers : "Authorization" : authenticationHeader ,
function (error, httpResponse, body)
const statusCode = httpResponse.statusCode;
httpResponse.pipe(filestream);
httpResponse.on('end', function ()
console.log("file complete");
filestream.close();
); );
The file size of input.wav is 0. Its not downloading file. Please help.
1 Answer
1
Your callback has an error
argument, which you are completely ignoring. Do something with this error, like print it out so your problem can tell you what you're doing wrong. I definitely see at least 1 problem in your source, and the error from request
should tell you what it is.
error
request
Edit On second thought the above code shouldn't even execute. You should share code that you tested yourself. There's typos in there.
console.log(statusCode) prints 200.
– Malar Kandasamy
Aug 13 at 9:38
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
save the file directly from the browser. check it's file format.
– Sarath Kumar
Aug 13 at 8:53