@Immutable public final class S3Utilities extends Object
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.| Modifier and Type | Class and Description |
|---|---|
static class |
S3Utilities.Builder
Builder class to construct
S3Utilities object |
| Modifier and Type | Method and Description |
|---|---|
static S3Utilities.Builder |
builder()
Creates a builder for
S3Utilities. |
URL |
getUrl(Consumer<GetUrlRequest.Builder> getUrlRequest)
Returns the URL for an object stored in Amazon S3.
|
URL |
getUrl(GetUrlRequest getUrlRequest)
Returns the URL for an object stored in Amazon S3.
|
S3Uri |
parseUri(URI uri)
Returns a parsed
S3Uri with which a user can easily retrieve the bucket, key, region, style, and query
parameters of the URI. |
public static S3Utilities.Builder builder()
S3Utilities.public URL getUrl(Consumer<GetUrlRequest.Builder> getUrlRequest)
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 GetUrlRequest.Builder avoiding the need to
create one manually via GetUrlRequest.builder()
getUrlRequest - A Consumer that will call methods on GetUrlRequest.Builder to create a request.SdkException - Generated Url is malformedpublic URL getUrl(GetUrlRequest getUrlRequest)
If same configuration options are set on both #GetUrlRequest and #S3Utilities objects (for example: region), the configuration set on the #GetUrlRequest takes precedence.
getUrlRequest - request to construct urlSdkException - Generated Url is malformedpublic S3Uri parseUri(URI uri)
S3Uri 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.
uri - The URI to be parsedS3Uri
Example Usage
Copyright © 2023. All rights reserved.