Managing an object's 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 <path_to_local_file> \
--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
: Set of custom metadata in the form of comma separatedkey-value
pairs. Keys must consist of ASCII characters only. The value may not exceed 2 KB.--endpoint-url
: Object Storage endpoint.
Use the S3 API upload method, e.g., via curl
.
Use curl
8.3.0
AWS_KEY_ID="<static_key_ID>"
AWS_SECRET_KEY="<secret_key>"
LOCAL_FILE="<path_to_local_file>"
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
: ID of the static access key.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 consist of ASCII characters only.META_VALUE_1
andMETA_VALUE_2
: Values of custom metadata. The value may not exceed 2 KB.
Getting object metadata
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 the object is placed in.--key
: Bucket object key.--endpoint-url
: Object Storage endpoint.
Use the S3 API getObjectMeta 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
: ID of the static access key.AWS_SECRET_KEY
: Secret key.BUCKET_NAME
: Name of the bucket the object is placed in.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
: Set of new custom metadata in the form of comma separatedkey-value
pairs. Keys must consist of ASCII characters only. The value may not exceed 2 KB.--metadata-directive
: Parameter indicating that the object metadata must be replaced with a new one.--endpoint-url
: Object Storage endpoint.
Use the S3 API copy 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
: ID of the static access key.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 consist of ASCII characters only.META_VALUE_1
andMETA_VALUE_2
: New values of custom metadata. The value may not exceed 2 KB.