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.)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With