Package io.micronaut.objectstorage.aws
Class AwsS3Operations
java.lang.Object
io.micronaut.objectstorage.aws.AwsS3Operations
- All Implemented Interfaces:
ObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse>
@EachBean(AwsS3Configuration.class)
@Requires(condition=ToggeableCondition.class) @Requires(beans=AwsS3Configuration.class)
public class AwsS3Operations
extends Object
implements ObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,software.amazon.awssdk.services.s3.model.PutObjectResponse,software.amazon.awssdk.services.s3.model.DeleteObjectResponse>
AWS implementation of
ObjectStorageOperations
.- Since:
- 1.0
- Author:
- Pavol Gressa
-
Constructor Summary
ConstructorsConstructorDescriptionAwsS3Operations
(AwsS3Configuration configuration, software.amazon.awssdk.services.s3.S3Client s3Client, InputStreamMapper inputStreamMapper) Deprecated, for removal: This API element is subject to removal in a future version.AwsS3Operations
(AwsS3Configuration configuration, software.amazon.awssdk.services.s3.S3Client s3Client, InputStreamMapper inputStreamMapper, @Nullable io.micronaut.context.env.Environment environment) Constructs an AwsS3Operations. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Copies an object stored atsourceKey
todestinationKey
, within the same object storage (bucket/container).@NonNull software.amazon.awssdk.services.s3.model.DeleteObjectResponse
Deletes an object from the object storage.boolean
Checks whether an entry with the given key exists in the object storage.protected @NonNull software.amazon.awssdk.core.sync.RequestBody
getRequestBody
(@NonNull UploadRequest uploadRequest) protected software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder
getRequestBuilder
(@NonNull UploadRequest request) Lists the objects that exist in the object storage.@NonNull PresignResponse
presign
(@NonNull PresignRequest request) Generates a pre-authorized (signed) request for the given operation.@NonNull Optional<AwsS3ObjectStorageEntry>
Gets the object from object storage.@NonNull UploadResponse<software.amazon.awssdk.services.s3.model.PutObjectResponse>
upload
(@NonNull UploadRequest uploadRequest) Uploads an object to the object storage.@NonNull UploadResponse<software.amazon.awssdk.services.s3.model.PutObjectResponse>
upload
(@NonNull UploadRequest request, @NonNull Consumer<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder> requestConsumer) Uploads an object to the object storage.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.objectstorage.ObjectStorageOperations
invalidatePresignedRequest
-
Constructor Details
-
AwsS3Operations
@Inject public AwsS3Operations(@Parameter AwsS3Configuration configuration, software.amazon.awssdk.services.s3.S3Client s3Client, InputStreamMapper inputStreamMapper, @Nullable @Nullable io.micronaut.context.env.Environment environment) Constructs an AwsS3Operations.- Parameters:
configuration
- AWS S3 Configuration.s3Client
- S3 Client.inputStreamMapper
- InputStream Mapper.environment
- If non-null, used to read theaws.region
property for presigning.
-
AwsS3Operations
@Deprecated(since="2.10.0", forRemoval=true) public AwsS3Operations(@Parameter AwsS3Configuration configuration, software.amazon.awssdk.services.s3.S3Client s3Client, InputStreamMapper inputStreamMapper) Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
configuration
- AWS S3 Configuration.s3Client
- S3 Client.inputStreamMapper
- InputStream Mapper.
-
-
Method Details
-
upload
@NonNull public @NonNull UploadResponse<software.amazon.awssdk.services.s3.model.PutObjectResponse> upload(@NonNull @NonNull UploadRequest uploadRequest) Description copied from interface:ObjectStorageOperations
Uploads an object to the object storage. If there is an existing entry, it will be updated.- Specified by:
upload
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
uploadRequest
- the upload request- Returns:
- the upload response
-
upload
@NonNull public @NonNull UploadResponse<software.amazon.awssdk.services.s3.model.PutObjectResponse> upload(@NonNull @NonNull UploadRequest request, @NonNull @NonNull Consumer<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder> requestConsumer) Description copied from interface:ObjectStorageOperations
Uploads an object to the object storage. If there is an existing entry, it will be updated.- Specified by:
upload
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
request
- the upload requestrequestConsumer
- Upload request builder consumer- Returns:
- the upload response
-
retrieve
Description copied from interface:ObjectStorageOperations
Gets the object from object storage.- Specified by:
retrieve
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
key
- the object path in the format/foo/bar/file
- Returns:
- the object, or empty optional if the object does not exist
-
delete
@NonNull public @NonNull software.amazon.awssdk.services.s3.model.DeleteObjectResponse delete(@NonNull @NonNull String key) Description copied from interface:ObjectStorageOperations
Deletes an object from the object storage.- Specified by:
delete
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
key
- object path in the format/foo/bar/file
- Returns:
- Cloud vendor-specific delete response.
-
exists
Description copied from interface:ObjectStorageOperations
Checks whether an entry with the given key exists in the object storage.- Specified by:
exists
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
key
- object path in the format/foo/bar/file
- Returns:
- true if the entry exists, false otherwise.
-
listObjects
Description copied from interface:ObjectStorageOperations
Lists the objects that exist in the object storage.- Specified by:
listObjects
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Returns:
- a set of keys (paths) of the existing objects, if any, or an empty list otherwise.
-
copy
Description copied from interface:ObjectStorageOperations
Copies an object stored atsourceKey
todestinationKey
, within the same object storage (bucket/container). If the destination exists, it will be overwritten.- Specified by:
copy
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
sourceKey
- the key of the source objectdestinationKey
- the key of the destination object
-
getRequestBuilder
@NonNull protected software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder getRequestBuilder(@NonNull @NonNull UploadRequest request) - Parameters:
request
- the upload request- Returns:
- An AWS'
PutObjectRequest.Builder
from a Micronaut'sUploadRequest
.
-
getRequestBody
@NonNull protected @NonNull software.amazon.awssdk.core.sync.RequestBody getRequestBody(@NonNull @NonNull UploadRequest uploadRequest) - Parameters:
uploadRequest
- the upload request- Returns:
- An AWS'
RequestBody
from a Micronaut'sUploadRequest
.
-
presign
Description copied from interface:ObjectStorageOperations
Generates a pre-authorized (signed) request for the given operation.- Specified by:
presign
in interfaceObjectStorageOperations<software.amazon.awssdk.services.s3.model.PutObjectRequest.Builder,
software.amazon.awssdk.services.s3.model.PutObjectResponse, software.amazon.awssdk.services.s3.model.DeleteObjectResponse> - Parameters:
request
- the presign request parameters- Returns:
- information with the generated URL and its expiration
-
AwsS3Operations(AwsS3Configuration, S3Client, InputStreamMapper, Environment)
.