Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Generating a read only signed url for a private object #134

Closed
radanskoric opened this issue Oct 16, 2014 · 2 comments
Closed

Generating a read only signed url for a private object #134

radanskoric opened this issue Oct 16, 2014 · 2 comments

Comments

@radanskoric
Copy link

Hi, in v1 we had S3Object#url_for but I can't find any equivalent in v2 on S3::Object?

@trevorrowe
Copy link
Contributor

The functionality exists, but it has not been exposed via S3::Object yet. You need to use the Aws::S3::Presigner class to generate a URL.

s3 = Aws::S3::Client.new
signer = Aws::S3::Presigner.new(client: s3)
url = signer.presigned_url(:get_object, bucket: "bucket-name", key: "object-key")
#=> "https://bucket-name.s3.amazonaws.com/object-key?..."

Ideally, this could be exposed from S3::Object in some fashion, e.g.:

obj = Aws::S3::Resource.new.bucket('bucket-name').object('object-key')
obj.presigned_url(:get)
#=> "https://bucket-name.s3.amazonaws.com/object-key?..."

# additional http verbs:
obj.presigned_url(:put)
obj.presigned_url(:head)
obj.presigned_url(:delete)

@radanskoric
Copy link
Author

Awesome, thank you for adding that so quickly. I decided to stick with v1 gem for now since the code in general tuns out much messier when implemented with v2. I'll checkout v2 again in a while.
Though, this particular addition looks very good. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants