How to download a multipart wav file from cloudant database and save locally using Node JS and REST API?

泪湿孤枕 提交于 2019-12-13 03:15:07

问题


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.



来源:https://stackoverflow.com/questions/51818270/how-to-download-a-multipart-wav-file-from-cloudant-database-and-save-locally-usi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!