Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get an object key from URL using AWS SDK (v2)

With the AWS SDK gem I can easily obtain an object URL given some parameters.

Example:

credentials = Aws::Credentials.new(ENV['S3_KEY'], ENV['S3_SECRET'])
s3 = Aws::S3::Resource.new(
    credentials: credentials,
    region: ENV['S3_REGION_KEY']
)
object = s3.bucket('my-bucket').object('path/to/file.ext')
url = object.public_url

Given a public URL, can I reverse it to obtain an Aws::S3::Object? Is there a method to do it using this SDK? Or should I split the URL manually? (I'd prefer to avoid this.)

like image 818
ProGM Avatar asked Jan 16 '15 09:01

ProGM


1 Answers

There's no way I have come across in ruby, however this class does exist in the Java SDK for AWS. So if you are going to create a Ruby implementation it is probably worthwhile using this for guidance

https://github.com/aws/aws-sdk-java/blob/806e98ecd35ba00d9dc0da35ab962c7caa76293c/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/AmazonS3URI.java

like image 89
goughy000 Avatar answered Oct 09 '22 04:10

goughy000