我不确定我在这里做错了什么...当我尝试使用nodejs上的knox库将视频(multipart)从android上传到AmazonS3时,我一直收到此错误...我也在使用异步库等待在我调用回调之前视频完成上传(cb)下一个函数这是我的错误:
2015-06-10T08:32:27.877193+00:00 app[web.1]: stream.on('error', fn);
2015-06-10T08:32:27.877195+00:00 app[web.1]: ^
2015-06-10T08:32:27.877196+00:00 app[web.1]: TypeError: undefined is not a function
2015-06-10T08:32:27.877198+00:00 app[web.1]: at Client.putStream (/app/node_modules/knox/lib/client.js:448:10)
2015-06-10T08:32:27.877200+00:00 app[web.1]: at setupAndCreateImage (/app/routes/challenge.js:397:11)
2015-06-10T08:32:27.877201+00:00 app[web.1]: at fn (/app/node_modules/async/lib/async.js:582:34)
2015-06-10T08:32:27.877202+00:00 app[web.1]: at Immediate._onImmediate (/app/node_modules/async/lib/async.js:498:34)
2015-06-10T08:32:27.877204+00:00 app[web.1]: at processImmediate [as _immediateCallback] (timers.js:358:17)
以下是代码:
function setupAndCreateImage ( cb) {
if(req.files && req.files.mediaFile) {
console.log("Received file:\n" + JSON.stringify(req.files));
//add p for pics will do v for vids
videoID = "v" + path.basename(req.files.mediaFile.path);
tmp_path = req.files.mediaFile.path;
//targetPathSmall = './public/img/challenges/' + videoID;
//videoConvert = req.files.mediaFile.name;
var video = req.files.mediaFile;
var s3Headers = {
'Content-Type': video.type,
'Content-Length': video.size,
'x-amz-acl': 'public-read'
};
//console.log('stdout:', stdout, targetPathSmall)
s3.putStream(tmp_path, videoID, s3Headers, function(err, s3response){
//handle, respond
if(err) {
console.log(err);
} else {
s3response.resume();
console.log("saved to S3");
//console.log(s3response);
cb(null, videoID);
}
});
} else {
videoID = "";
cb(null, videoID);
}
},
答案 0 :(得分:1)
您将String作为第一个参数传递给s3.putStream
,其中包含Stream。
请参阅https://github.com/Automattic/knox/blob/master/lib/client.js#L398
你应该像这样使用它:
s3.putStream(inputStream, videoID, s3Headers, function(err, s3response) {
如果可能,您可以通过阅读inputStream
的内容来填充req.mediaFile
。从代码中辨别出来并不容易。