1) Directly using the builder()
method. You have to manually specify the configuration params like region, s3Configuration on the builder.
S3Utilities utilities = S3Utilities.builder().region(Region.US_WEST_2).build() GetUrlRequest request = GetUrlRequest.builder().bucket("foo-bucket").key("key-without-spaces").build(); URL url = utilities.getUrl(request);
2) Using the low-level client S3Client.utilities()
method. This is recommended as SDK will use the same configuration from the S3Client
object to create the S3Utilities
object.
S3Client s3client = S3Client.create(); S3Utilities utilities = s3client.utilities(); GetUrlRequest request = GetUrlRequest.builder().bucket("foo-bucket").key("key-without-spaces").build(); URL url = utilities.getUrl(request);Note: This class does not make network calls.
Nested Class Summary
Nested Classes
static final class
Method Summary
All MethodsStatic MethodsInstance MethodsConcrete Methods
Returns the URL for an object stored in Amazon S3.
Returns the URL for an object stored in Amazon S3.
Returns a parsedS3Uri
with which a user can easily retrieve the bucket, key, region, style, and query parameters of the URI.
Method Details
builder
getUrl
Returns the URL for an object stored in Amazon S3. If the object identified by the given bucket and key has public read permissions, then this URL can be directly accessed to retrieve the object's data.If same configuration options are set on both #GetUrlRequest and #S3Utilities objects (for example: region), the configuration set on the #GetUrlRequest takes precedence.
This is a convenience which creates an instance of the
Parameters:GetUrlRequest.Builder
avoiding the need to create one manually viaGetUrlRequest.builder()
getUrlRequest
- AConsumer
that will call methods onGetUrlRequest.Builder
to create a request. Returns: A URL for an object stored in Amazon S3. Throws:SdkException
- Generated Url is malformedgetUrl
Returns the URL for an object stored in Amazon S3. If the object identified by the given bucket and key has public read permissions, then this URL can be directly accessed to retrieve the object's data.If same configuration options are set on both #GetUrlRequest and #S3Utilities objects (for example: region), the configuration set on the #GetUrlRequest takes precedence.
Parameters:getUrlRequest
- request to construct url Returns: A URL for an object stored in Amazon S3. Throws:SdkException
- Generated Url is malformedparseUri
Returns a parsedS3Uri
with which a user can easily retrieve the bucket, key, region, style, and query parameters of the URI. Only path-style and virtual-hosted-style URI parsing is supported, including CLI-style URIs, e.g., "s3://bucket/key". AccessPoints and Outposts URI parsing is not supported. If you work with object keys and/or query parameters with special characters, they must be URL-encoded, e.g., replace " " with "%20". If you work with virtual-hosted-style URIs with bucket names that contain a dot, i.e., ".", the dot must not be URL-encoded. Encoded buckets, keys, and query parameters will be returned decoded.For more information on path-style and virtual-hosted-style URIs, see Methods for accessing a bucket.
Parameters:uri
- The URI to be parsed Returns: ParsedS3Uri
Example Usage
CopyS3Client s3Client = S3Client.create(); S3Utilities s3Utilities = s3Client.utilities(); String uriString = "https://myBucket.s3.us-west-1.amazonaws.com/doc.txt?versionId=abc123"; URI uri = URI.create(uriString); S3Uri s3Uri = s3Utilities.parseUri(uri); String bucket = s3Uri.bucket().orElse(null); // "myBucket" String key = s3Uri.key().orElse(null); // "doc.txt" Region region = s3Uri.region().orElse(null); // Region.US_WEST_1 boolean isPathStyle = s3Uri.isPathStyle(); // false String versionId = s3Uri.firstMatchingRawQueryParameter("versionId").orElse(null); // "abc123"
ncG1vNJzZmirlKB7ornAs6anmaeoe6S7zGihmq6RZK6xtY6lmK2do6l8tLvFra6aqpVkrq6t2ailaJmnqMClt46snKuumZiytHvSbGaMa4Wptq2106KcrGaYqbqt