1

It's pretty straightforward but I have this issue: Unexpected error while processing request: undefined method `PresignedPost' for Aws::S3:Module

My objective: Get the presigned URL for an object to which I can perform an upload file.

My gem has

gem 'aws-sdk', '~> 2'

Code:

@@aws_creds = Aws::SharedCredentials.new(profile_name: profile)

Aws.config.update({region: 'us-west-2',credentials: @@aws_creds})
s3 = Aws::S3::Resource.new
@bucket = s3.bucket(bucketName)
form = Aws::S3::PresignedPost(:key => key )
if(form)
  form.fields
end
premunk
  • 303
  • 1
  • 4
  • 18
  • You implementation is wrong. `PresignedPost()` is trying to act as a method you might want `PresignedPost.new()` but you will have to pass the credentials, the region and the bucket. [See Docs](http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/PresignedPost.html) – engineersmnky Jul 30 '15 at 18:35
  • omg I get it. how dumb of me. – premunk Jul 30 '15 at 18:36
  • 1
    Yes in the documentation the top section called **Basic Usage** offers an example. AWS SDK is extremely well documented (which is great because the source implements a ton of automagic). Also as @mircea pointed out you can issue one directly from the bucket instance using [`Bucket#presigned_post`](http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Bucket.html#presigned_post-instance_method) which will eliminate the need to resupply credentials/region/bucket. – engineersmnky Jul 30 '15 at 18:39

1 Answers1

2

you normally don't do a standalone presignedpost. you do it using the bucket method.
something like @bucket.presigned_post(:key=>key)

See doc: http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/PresignedPost.html

Note: Normally you do not need to construct a PresignedPost yourself. See Bucket#presigned_post and Object#presigned_post.

Mircea
  • 10,216
  • 2
  • 30
  • 46
  • Implemented it. But I keep getting this error: Unexpected error while processing request: undefined method `access_key_id' for nil:NilClass Any idea why? – premunk Jul 30 '15 at 18:51
  • guess is that you are not loading the credentials. Look at the client loading credential here: http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html – Mircea Jul 30 '15 at 19:14
  • also this part does not make too much sense to me: Aws.config.update – Mircea Jul 30 '15 at 19:21
  • 1
    you would normally want to pass into the client creation – Mircea Jul 30 '15 at 19:23
  • 1
    YAY. Did all that! Thank you, all. – premunk Jul 30 '15 at 19:59