Class S3Utilities
- java.lang.Object
-
- software.amazon.awssdk.services.s3.S3Utilities
-
@Immutable @ThreadSafe public final class S3Utilities extends Object
Utilities for working with Amazon S3 objects. An instance of this class can be created by: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 theS3Client
object to create theS3Utilities
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 Modifier and Type Class Description static class
S3Utilities.Builder
Builder class to constructS3Utilities
object
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static S3Utilities.Builder
builder()
Creates a builder forS3Utilities
.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 parsedS3Uri
with which a user can easily retrieve the bucket, key, region, style, and query parameters of the URI.
-
-
-
Method Detail
-
builder
public static S3Utilities.Builder builder()
Creates a builder forS3Utilities
.
-
getUrl
public URL getUrl(Consumer<GetUrlRequest.Builder> getUrlRequest)
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
GetUrlRequest.Builder
avoiding the need to create one manually viaGetUrlRequest.builder()
- Parameters:
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 malformed
-
getUrl
public URL getUrl(GetUrlRequest getUrlRequest)
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 malformed
-
parseUri
public S3Uri parseUri(URI uri)
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:
- Parsed
S3Uri
Example Usage
-
-