Managing object custom metadata
When uploading an object to Object Storage, you can provide a set of custom metadata in the form of key-value
pairs.
Uploading an object with metadata
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api put-object \
--bucket <bucket_name> \
--key <object_key> \
--body <local_file_path> \
--metadata "<key_1>"="<value_1>","<key_2>"="<value_2>" \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Name of the bucket you want to upload the object to.--key
: Bucket object key.--body
: Path to the local file you want to upload to the bucket.--metadata
: Custom metadata provided as comma-separatedkey-value
pairs. Keys must only consist of ASCII characters . The value may not exceed 2 KB.--endpoint-url
: Object Storage endpoint.
Use the upload S3 API method, e.g., via curl
.
Use curl
8.3.0
AWS_KEY_ID="<static_key_ID>"
AWS_SECRET_KEY="<secret_key>"
LOCAL_FILE="<local_file_path>"
BUCKET_NAME="<bucket_name>"
OBJECT_PATH="<object_key>"
META_KEY_1="<key_1>"
META_VALUE_1="<value_1>"
META_KEY_2="<key_2>"
META_VALUE_2="<value_2>"
curl \
--request PUT \
--user "${AWS_KEY_ID}:${AWS_SECRET_KEY}" \
--aws-sigv4 "aws:amz:ru-central1:s3" \
--upload-file "${LOCAL_FILE}" \
--header "X-Amz-Meta-${META_KEY_1}: ${META_VALUE_1}" \
--header "X-Amz-Meta-${META_KEY_2}: ${META_VALUE_2}" \
--verbose \
"https://storage.yandexcloud.net/${BUCKET_NAME}/${OBJECT_PATH}"
Where:
AWS_KEY_ID
: Static access key ID.AWS_SECRET_KEY
: Secret key.LOCAL_FILE
: Path to the local file you want to upload to the bucket.BUCKET_NAME
: Name of the bucket you want to upload the object to.OBJECT_PATH
: Bucket object key.META_KEY_1
andMETA_KEY_1
: Custom metadata keys. Keys must only consist of ASCII characters .META_VALUE_1
andMETA_VALUE_2
: Custom metadata values. The value may not exceed 2 KB.
Getting object metadata
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to get the object metadata:
yc storage s3api head-object --help
-
Get a list of buckets in the default folder:
yc storage bucket list
Result:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Run this command:
yc storage s3api head-object \ --bucket <bucket_name> \ --key <object_key>
Where:
--bucket
: Name of your bucket.--key
: Object key.
Result:
etag: '"d41d8cd98f00b204e9800998********"' request_id: 6428ce25******** accept_ranges: bytes content_type: application/octet-stream last_modified_at: "2024-10-08T12:36:36Z" server_side_encryption: aws:kms sse_kms_key_id: abj497vtg3h0********
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api head-object \
--bucket <bucket_name> \
--key <object_key> \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Name of the bucket containing the object.--key
: Bucket object key.--endpoint-url
: Object Storage endpoint.
Use the getObjectMeta S3 API method, e.g., via curl
.
Use curl
8.3.0
AWS_KEY_ID="<static_key_ID>"
AWS_SECRET_KEY="<secret_key>"
BUCKET_NAME="<bucket_name>"
OBJECT_PATH="<object_key>"
curl \
--head \
--user "${AWS_KEY_ID}:${AWS_SECRET_KEY}" \
--aws-sigv4 "aws:amz:ru-central1:s3" \
"https://storage.yandexcloud.net/${BUCKET_NAME}/${OBJECT_PATH}"
Where:
AWS_KEY_ID
: Static access key ID.AWS_SECRET_KEY
: Secret key.BUCKET_NAME
: Name of the bucket containing the object.OBJECT_PATH
: Bucket object key.
Editing object metadata
Warning
The existing set of custom metadata will be completely overwritten by the new one.
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api copy-object \
--bucket <bucket_name> \
--key <object_key> \
--copy-source <bucket_name>/<object_key> \
--metadata "<key_1>"="<value_1>","<key_2>"="<value_2>" \
--metadata-directive REPLACE \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Name of the bucket you want to edit the object metadata in.--key
: Bucket object key.--copy-source
: Path to the object in<bucket_name>/<object_key>
format.--metadata
: New custom metadata provided as comma-separatedkey-value
pairs. Keys must only consist of ASCII characters . The value may not exceed 2 KB.--metadata-directive
: Parameter indicating that the object metadata must be replaced with new metadata.--endpoint-url
: Object Storage endpoint.
Use the copy S3 API method, e.g., via curl
.
Use curl
8.3.0
AWS_KEY_ID="<static_key_ID>"
AWS_SECRET_KEY="<secret_key>"
BUCKET_NAME="<bucket_name>"
OBJECT_PATH="<object_key>"
META_KEY_1="<key_1>"
META_VALUE_1="<value_1>"
META_KEY_2="<key_2>"
META_VALUE_2="<value_2>"
curl \
--request PUT \
--user "${AWS_KEY_ID}:${AWS_SECRET_KEY}" \
--aws-sigv4 "aws:amz:ru-central1:s3" \
--header "X-Amz-Copy-Source: /${BUCKET_NAME}/${OBJECT_PATH}" \
--header "X-Amz-Metadata-Directive: REPLACE" \
--header "X-Amz-Meta-${META_KEY_1}: ${META_VALUE_1}" \
--header "X-Amz-Meta-${META_KEY_2}: ${META_VALUE_2}" \
--verbose \
"https://storage.yandexcloud.net/${BUCKET_NAME}/${OBJECT_PATH}"
Where:
AWS_KEY_ID
: Static access key ID.AWS_SECRET_KEY
: Secret key.BUCKET_NAME
: Name of the bucket you want to edit the object metadata in.OBJECT_PATH
: Bucket object key.META_KEY_1
andMETA_KEY_1
: New custom metadata keys. Keys must only consist of ASCII characters .META_VALUE_1
andMETA_VALUE_2
: New custom metadata values. The value may not exceed 2 KB.