I'm using the 2.x AWS Java SDK (https://docs.aws.amazon.com/sdk-for-java/index.html). I need to get an S3 object using the friendly HTTP URL (e.g. https://bucket.s3.region.amazonaws.com/key
or https://s3.region.amazonaws.com/bucket/key
).
The old SDK included an AmazonS3URI
class that could parse a URL and extract the bucket and key. Does the 2.x SDK include similar functionality, or should I use Java's URI class to parse the URL?
In order to get the URL of an S3 Object via the AWS Console:Navigate to the AWS S3 console and click on your bucket's name. Use the search input to find the object if necessary. Click on the checkbox next to the object's name. Click on the Copy URL button.
You can get the resource URL either by calling getResourceUrl or getUrl . AmazonS3Client s3Client = (AmazonS3Client)AmazonS3ClientBuilder. defaultClient(); s3Client. putObject(new PutObjectRequest("your-bucket", "some-path/some-key.
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for.
This is what I did using URI
from java.net
:
URI uri = new URI(s3Url);
String bucketName = uri.getHost();
// remove the first "/"
String prefix = uri.getPath().substring(1);
There isn't a way to do it with the SDK yet, but it might be available in the future. In the meantime, you can write your own code using Java's URI
class, or use AmazonS3URI
from the old SDK and hope it keeps working.
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