Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Object.keys called on non-object when uploading with knox

I'm using knox (https://github.com/LearnBoost/knox) to upload a file to Amazon S3. I have just moved my node app to Amazon EC2 and have the following error when uploading with knox. I appear to have all of the libraries installed. The same code was OK on nodejitsu. I'm quite new to node / JS so I'm not sure what this means.

/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)
like image 752
Shocks Avatar asked Nov 11 '22 02:11

Shocks


1 Answers

Perhaps, you, like me, were passing the "mimetype" string as third parameter in client.putFile() function...

You must pass an object specifying the content type headers:

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

or just ignore the third parameter (like I did):

client.putFile(localPath, s3Path, function(err, result) {});
like image 170
2 revs Avatar answered Nov 14 '22 22:11

2 revs