TypeError:使用knox上传时在非对象上调用Object.keys

时间:2014-09-02 11:03:17

标签: node.js knox-amazon-s3-client

我正在使用knox(https://github.com/LearnBoost/knox)将文件上传到Amazon S3。我刚刚将我的节点应用程序移动到Amazon EC2,并在使用knox上传时出现以下错误。我似乎安装了所有库。 nodejitsu上的代码相同。我对node / JS很新,所以我不确定这意味着什么。

/home/ec2-user/foo/node_modules/knox/lib/auth.js:208
Object.keys(url.query).forEach(function (key) {
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Object.exports.canonicalizeResource (/home/ec2-user/foo/node_modules/knox/lib/auth.js:208:10)
at Client.request (/home/ec2-user/foo/node_modules/knox/lib/client.js:275:22)
at Client.put (/home/ec2-user/foo/node_modules/knox/lib/client.js:326:15)
at Client.putStream (/home/ec2-user/foo/node_modules/knox/lib/client.js:408:18)
at /home/ec2-user/foo/node_modules/knox/lib/client.js:378:20
at Object.oncomplete (fs.js:93:15)

1 个答案:

答案 0 :(得分:1)

也许,你和我一样,正在传递" mimetype" string作为client.putFile()函数中的第三个参数...

您必须传递指定内容类型标题的对象:

client.putFile(localPath, s3Path, {'Content-Type': mimetype}  ,function(err, result) {});

或者只是忽略第三个参数(就像我做的那样):

client.putFile(localPath, s3Path, function(err, result) {});