putObjectAnnotation method

Future<PutObjectAnnotationOutput> putObjectAnnotation({
  1. required String annotationName,
  2. required Uint8List annotationPayload,
  3. required String bucket,
  4. required String key,
  5. ChecksumAlgorithm? checksumAlgorithm,
  6. String? checksumCRC32,
  7. String? checksumCRC32C,
  8. String? checksumCRC64NVME,
  9. String? checksumMD5,
  10. String? checksumSHA1,
  11. String? checksumSHA256,
  12. String? checksumSHA512,
  13. String? checksumXXHASH128,
  14. String? checksumXXHASH3,
  15. String? checksumXXHASH64,
  16. String? contentMD5,
  17. String? expectedBucketOwner,
  18. String? objectIfMatch,
  19. RequestPayer? requestPayer,
  20. String? versionId,
})

Attaches an annotation to an Amazon S3 object. An annotation is a named payload of 1 byte to 1 MiB that you can associate with a specific object or object version. Each object can have up to 1,000 annotations.

For annotation naming rules and restrictions, see Annotation naming guidelines in the Amazon S3 User Guide.

Annotations inherit the encryption of their parent object. For objects without server-side encryption, annotations are encrypted with SSE-S3 (the default for new objects). Objects encrypted with SSE-C cannot have annotations.

To use this operation, you must have the s3:PutObjectAnnotation permission. If the bucket has Requester Pays enabled, you must include the x-amz-request-payer header. The following operations are related to PutObjectAnnotation:

May throw AnnotationLimitExceeded. May throw AnnotationNameTooLong. May throw InvalidAnnotationName. May throw InvalidRequest. May throw NoSuchBucket. May throw NoSuchKey. May throw UnsupportedMediaType.

Parameter annotationName : The name of the annotation.

Length Constraints: Minimum length of 1. Maximum length of 512 bytes.

Parameter annotationPayload : The annotation payload. Must be between 1 byte and 1 MiB in size, and must be valid UTF-8 encoded text. If the payload contains invalid UTF-8 bytes, the request fails with HTTP 415 (Unsupported Media Type). To store binary data, encode the payload using Base64 before uploading.

Parameter bucket : The name of the bucket that contains the object.

Parameter key : The object key.

Parameter checksumAlgorithm : The checksum algorithm to use. Supported values: CRC32, CRC32C, CRC64NVME, SHA1, SHA256, SHA512, MD5, XXHASH64, XXHASH3, XXHASH128.

Parameter checksumCRC32 : Base64-encoded CRC32 checksum of the annotation payload.

Parameter checksumCRC32C : Base64-encoded CRC32C checksum of the annotation payload.

Parameter checksumCRC64NVME : Base64-encoded CRC64NVME checksum of the annotation payload.

Parameter checksumMD5 : Base64-encoded MD5 checksum of the annotation payload.

Parameter checksumSHA1 : Base64-encoded SHA1 checksum of the annotation payload.

Parameter checksumSHA256 : Base64-encoded SHA256 checksum of the annotation payload.

Parameter checksumSHA512 : Base64-encoded SHA512 checksum of the annotation payload.

Parameter checksumXXHASH128 : Base64-encoded XXHASH128 checksum of the annotation payload.

Parameter checksumXXHASH3 : Base64-encoded XXHASH3 checksum of the annotation payload.

Parameter checksumXXHASH64 : Base64-encoded XXHASH64 checksum of the annotation payload.

Parameter contentMD5 : Base64-encoded MD5 digest of the message.

Parameter expectedBucketOwner : The account ID of the expected bucket owner. If the bucket is owned by a different account, the request fails with an HTTP 403 (Access Denied) error.

Parameter objectIfMatch : If specified, the operation only succeeds if the object's ETag matches the provided value.

Parameter versionId : The version ID of the object to attach the annotation to.

Implementation

Future<PutObjectAnnotationOutput> putObjectAnnotation({
  required String annotationName,
  required Uint8List annotationPayload,
  required String bucket,
  required String key,
  ChecksumAlgorithm? checksumAlgorithm,
  String? checksumCRC32,
  String? checksumCRC32C,
  String? checksumCRC64NVME,
  String? checksumMD5,
  String? checksumSHA1,
  String? checksumSHA256,
  String? checksumSHA512,
  String? checksumXXHASH128,
  String? checksumXXHASH3,
  String? checksumXXHASH64,
  String? contentMD5,
  String? expectedBucketOwner,
  String? objectIfMatch,
  RequestPayer? requestPayer,
  String? versionId,
}) async {
  final headers = <String, String>{
    if (checksumAlgorithm != null)
      'x-amz-sdk-checksum-algorithm': checksumAlgorithm.value,
    if (checksumCRC32 != null)
      'x-amz-checksum-crc32': checksumCRC32.toString(),
    if (checksumCRC32C != null)
      'x-amz-checksum-crc32c': checksumCRC32C.toString(),
    if (checksumCRC64NVME != null)
      'x-amz-checksum-crc64nvme': checksumCRC64NVME.toString(),
    if (checksumMD5 != null) 'x-amz-checksum-md5': checksumMD5.toString(),
    if (checksumSHA1 != null) 'x-amz-checksum-sha1': checksumSHA1.toString(),
    if (checksumSHA256 != null)
      'x-amz-checksum-sha256': checksumSHA256.toString(),
    if (checksumSHA512 != null)
      'x-amz-checksum-sha512': checksumSHA512.toString(),
    if (checksumXXHASH128 != null)
      'x-amz-checksum-xxhash128': checksumXXHASH128.toString(),
    if (checksumXXHASH3 != null)
      'x-amz-checksum-xxhash3': checksumXXHASH3.toString(),
    if (checksumXXHASH64 != null)
      'x-amz-checksum-xxhash64': checksumXXHASH64.toString(),
    if (contentMD5 != null) 'Content-MD5': contentMD5.toString(),
    if (expectedBucketOwner != null)
      'x-amz-expected-bucket-owner': expectedBucketOwner.toString(),
    if (objectIfMatch != null)
      'x-amz-object-if-match': objectIfMatch.toString(),
    if (requestPayer != null) 'x-amz-request-payer': requestPayer.value,
  };
  final $query = <String, List<String>>{
    'annotationName': [annotationName],
    if (versionId != null) 'versionId': [versionId],
  };
  final $result = await _protocol.sendRaw(
    method: 'PUT',
    requestUri:
        '/${key.split('/').map(Uri.encodeComponent).join('/')}?annotation',
    queryParams: $query,
    headers: headers,
    payload: annotationPayload,
    endpoint: _resolveEndpoint(
      bucket: bucket,
      key: key,
    ),
    exceptionFnMap: _exceptionFns,
  );
  final $elem = await _s.xmlFromResponse($result);
  return PutObjectAnnotationOutput(
    annotationName: _s.extractXmlStringValue($elem, 'AnnotationName'),
    key: _s.extractXmlStringValue($elem, 'Key'),
    checksumCRC32:
        _s.extractHeaderStringValue($result.headers, 'x-amz-checksum-crc32'),
    checksumCRC32C:
        _s.extractHeaderStringValue($result.headers, 'x-amz-checksum-crc32c'),
    checksumCRC64NVME: _s.extractHeaderStringValue(
        $result.headers, 'x-amz-checksum-crc64nvme'),
    checksumMD5:
        _s.extractHeaderStringValue($result.headers, 'x-amz-checksum-md5'),
    checksumSHA1:
        _s.extractHeaderStringValue($result.headers, 'x-amz-checksum-sha1'),
    checksumSHA256:
        _s.extractHeaderStringValue($result.headers, 'x-amz-checksum-sha256'),
    checksumSHA512:
        _s.extractHeaderStringValue($result.headers, 'x-amz-checksum-sha512'),
    checksumType: _s
        .extractHeaderStringValue($result.headers, 'x-amz-checksum-type')
        ?.let(ChecksumType.fromString),
    checksumXXHASH128: _s.extractHeaderStringValue(
        $result.headers, 'x-amz-checksum-xxhash128'),
    checksumXXHASH3: _s.extractHeaderStringValue(
        $result.headers, 'x-amz-checksum-xxhash3'),
    checksumXXHASH64: _s.extractHeaderStringValue(
        $result.headers, 'x-amz-checksum-xxhash64'),
    eTag: _s.extractHeaderStringValue($result.headers, 'ETag'),
    objectVersionId: _s.extractHeaderStringValue(
        $result.headers, 'x-amz-object-version-id'),
    requestCharged: _s
        .extractHeaderStringValue($result.headers, 'x-amz-request-charged')
        ?.let(RequestCharged.fromString),
    serverSideEncryption: _s
        .extractHeaderStringValue(
            $result.headers, 'x-amz-server-side-encryption')
        ?.let(ServerSideEncryption.fromString),
  );
}