How to download a multipart wav file from cloudant

2019-09-01 04:57发布

问题:

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.

Here is the code for REST API:

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:

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.

Edit On second thought the above code shouldn't even execute. You should share code that you tested yourself. There's typos in there.