问题描述
我被困在使用Node JS API从cloudant检索多部分的问题。因此,我使用REST API从cloudant数据库下载了wav文件。但它不是从https URL下载wav文件。当我直接在浏览器中输入https URL时,它提示我将文件保存在本地。因此,URL是正确的。
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();
}); });
input.wav的文件大小为0。它没有下载文件。请帮忙。
The file size of input.wav is 0. Its not downloading file. Please help.
推荐答案
您的回调函数有一个 error
参数,您完全可以忽略它。处理此错误,例如将其打印出来,以便您的问题可以告诉您您在做什么错。我肯定在您的来源中至少看到了一个问题,并且 request
发出的错误应该告诉您它是什么。
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.
这篇关于如何从Cloudant数据库下载多部分的wav文件并使用Node JS和REST API在本地保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!