1

I'm trying to stream a webshot upload to S3. When I put together the AWS S3 object, I'm being told it has no 'upload' method:

var s3obj = new aws.S3({params: {Bucket: 'whatever', Key: 'idksomefile' }});
s3obj.upload({Body: body}).
              on('httpUploadProgress', function(evt) { console.log(evt); }).
              send(function(err, data) { console.log(err, data) });

I'm getting the following error:

TypeError: Object [object Object] has no method 'upload'

Any idea why this is exploding?

2 Answers 2

1

When you create s3obj from aws.S3 you should only pass a Bucket parameter, and then set the Key in the upload method parameters.

From the AWS documentation: found here

var s3obj = new aws.S3({params: {Bucket: 'whatever'}});
s3obj.upload({Key: 'idksomefile', Body: body}).
              on('httpUploadProgress', function(evt) { console.log(evt); }).
              send(function(err, data) { console.log(err, data) });

UPDATE 1:

Your body variable may be a Stream object, in which case you will need to use .toString():

var s3obj = new aws.S3({params: {Bucket: 'whatever'}});
s3obj.upload({Key: 'idksomefile', Body: body.toString()}).
              on('httpUploadProgress', function(evt) { console.log(evt); }).
              send(function(err, data) { console.log(err, data) });
4
  • No dice on this one, either. Just seems like the s3 object doesn't have the upload method at all.
    – opticon
    Feb 23, 2015 at 21:55
  • Silly question, but are you sure you're authenticated? What do you get if you console.log(s3obj) ??
    – theVinchi
    Feb 23, 2015 at 22:20
  • What should I see if I AM authenticated? Lots of code to post. It should be all good. Updating to 2.1.13 as advised about got me past the missing method error - getting a different error now: stream has no method 'read'
    – opticon
    Feb 23, 2015 at 22:22
  • 1
    Is your body variable a Stream? If so, you'll need to change to body.toString()
    – theVinchi
    Feb 23, 2015 at 22:27
0

EDIT 1: Please check your aws-sdk version and make sure its 2.1.13 to later.

Try to specify the key inside the upload function. see example

var s3obj = new aws.S3({params: {Bucket: 'whatever'}});
s3obj.upload({Key: 'idksomefile', Body: body}).
              on('httpUploadProgress', function(evt) { console.log(evt); }).
              send(function(err, data) { console.log(err, data) });
4
  • No dice on that. Still get the same error. I'm really stumped here - this seems to be a problem unique to me :P
    – opticon
    Feb 23, 2015 at 21:55
  • did you require the AWS Node.JS SDK as the variable aws? Feb 23, 2015 at 21:56
  • Yep. Everything seems to be kosher.
    – opticon
    Feb 23, 2015 at 22:03
  • Re: Edit 1 - Seems to be good now! Onto the next problem: object #<Stream> has no method 'read'!
    – opticon
    Feb 23, 2015 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.