简体   繁体   中英

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.)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM