不断收到功能错误不知道为什么
Keep getting function error not sure why
不确定我在这里做错了什么...尝试使用 nodejs 上的 knox 库将视频(多部分)从 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);
}
},
您将一个字符串作为第一个参数传递给 s3.putStream
,其中需要一个流。
见https://github.com/Automattic/knox/blob/master/lib/client.js#L398
你应该这样使用它:
s3.putStream(inputStream, videoID, s3Headers, function(err, s3response) {
如果可能,您可以通过读取 req.mediaFile
的内容作为流来填充 inputStream
。从代码上不太容易看出来
祝你好运!
不确定我在这里做错了什么...尝试使用 nodejs 上的 knox 库将视频(多部分)从 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);
}
},
您将一个字符串作为第一个参数传递给 s3.putStream
,其中需要一个流。
见https://github.com/Automattic/knox/blob/master/lib/client.js#L398
你应该这样使用它:
s3.putStream(inputStream, videoID, s3Headers, function(err, s3response) {
如果可能,您可以通过读取 req.mediaFile
的内容作为流来填充 inputStream
。从代码上不太容易看出来
祝你好运!