【发布时间】:2014-02-21 13:23:40
【问题描述】:
我正在尝试使用 Node.js 中请求包的 request.post() 将一个大文件发布到另一台服务器,我得到:
(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.
RangeError: Maximum call stack size exceeded
我认为这是因为它是一个大文件(80MB),因为较小的文件可以正常工作,所以我现在正在尝试实现一个流:
var options = {
url: aURLIHaveDefined,
headers: {
'User-Agent': 'MyRestAPI'
},
auth: {
username: creds.username,
password: creds.password
},
strictSSL: false,
json: true
}
var readStream = fs.createReadStream(filePathIHaveDefined);
readStream.pipe(options);
我得到了错误:
TypeError: Object #<Object> has no method 'on'
有谁知道在管道中包含选项的语法以及为什么会出现此错误?
更新(索萨评论后): 我试过了:
readStream.pipe(request(options));
readStream.on('end', function() {
console.log('end of readStream'+fileName);
});
它没有出错,但它现在似乎也没有做任何事情。该程序只是执行,我从来没有看到console.log()?
更新 #2:
使用帮助手册here,发现可以这样做:
fs.createReadStream('file.json').pipe(request.put('http://....'))
所以我在管道内添加了request.post(),看起来我快到了!使用:
readStream.pipe(
request.post(options,
function(error, response, data) {
if (error) {
console.log(": Cannot upload file to " + creds.server + " due to " + error);
setImmediate(failureCallback(error));
} else {
console.log(": file uploaded to " + data);
// send back data, which is url of uploaded file
setImmediate( successCallback(data) );
}
}
)
);
我收到一条错误消息,提示需要知道长度:
Apache Tomcat/5.5.17 - 错误报告 HTTP 状态 411 - 需要长度 如果没有定义的内容长度(长度 必填)。
【问题讨论】:
标签: node.js httprequest