I am storing one public object in AWS S3 bucket using given java API in my server Now i need to return back the public URL of the S3 object to my client
Till now i have'nt found any API call that can return the public URL(or link field) of a S3 object
Is there any way to get the URL??
Amazon Web Services (AWS) S3 objects are private by default. Only the object owner has permission to access these objects. Optionally we can set bucket policy to whitelist some accounts or URLs to access the objects of our S3 bucket.
To create a valid pre-signed URL for your object, you must provide your security credentials, specify a bucket name, an object key, specify the HTTP method (for instance the method is "GET" to download the object) and expiration date and time. Anyone who receives the pre-signed URL can then access the object.
For Java SDK 2
s3Client.utilities().getUrl(builder -> builder.bucket(AWS_BUCKET).key(s3RelativeFilePath)).toExternalForm();
Reference - https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3Utilities.html#getUrl-java.util.function.Consumer-
older versions had:
s3Client.getResourceUrl(bucket, s3RelativeToBucketPath);
For SDK-2 version, Kotlin:
s3.utilities().getUrl { it.bucket("BUCKET").key("FILEPATH") }.toExternalForm()
i am using aws-java-sdk-s3 1.11.58
accepted answer not working on this version.
below line works for this version
s3Client.getUrl(AWS_BUCKET, s3RelativeFilePath).toExternalForm();
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