set-meta (Manage object metadata)
Object metadata describes the properties of an object. It consists of two types: standard HTTP headers and user-defined metadata. You can use HTTP headers to customize policies for HTTP requests and user-defined metadata to identify the purpose or attributes of an object. You can use the set-meta command to set, modify, or delete the metadata for uploaded objects.
Usage notes
-
To set metadata for a single object, you must have the
oss:GetObject,oss:PutObject,oss:GetObjectVersion, andoss:GetObjectAclpermissions. To set metadata for multiple objects in a batch operation, you must have theoss:GetObject,oss:PutObject,oss:GetObjectVersion, andoss:ListObjectspermissions. For more information, see Attach a custom access policy to a RAM user. -
For ossutil 1.6.16 and later, you can use ossutil as the binary name in the command line. You do not need to replace the binary name based on your operating system. If your ossutil version is earlier than 1.6.16, you must replace the binary name based on your operating system. For more information, see ossutil command reference.
-
After you set or update object metadata using the set-meta command, you can view the object metadata using the stat command. For more information, see stat.
Command syntax
ossutil set-meta oss://bucketname[/prefix]
[header:value#header:value...]
[--update]
[--delete]
[-r, --recursive]
[-f, --force]
[--object-file <value>]
[--snapshot-path <value>]
[--disable-ignore-error]
[--version-id <value>]
[--include <value>]
[--exclude <value>]
The following describes the parameters and options:
|
Parameter or option |
Description |
|
bucketname |
The name of the bucket. |
|
prefix |
Resources in a bucket include folders and files. |
|
header:value#header:value... |
The metadata, specified as key-value pairs. Header keys are not case-sensitive, but values are case-sensitive. To set multiple metadata headers, separate them with number signs (#). Example: The following headers are available:
For more information about how to use headers, see Manage object metadata. |
|
--update |
Updates object metadata. This option can be abbreviated to -u and cannot be used with the --delete option. |
|
--delete |
Deletes object metadata. This option cannot be used with the --update option. |
|
-r, --recursive |
Sets metadata for all objects that match the specified prefix. If you do not specify this option, ossutil sets metadata only for the specified object. |
|
-f, --force |
Forces the operation without a confirmation prompt. |
|
--object-file |
Use this option to set, update, or delete metadata for multiple objects in a batch operation. The steps are as follows:
Note
If an error occurs on an object, ossutil records the error message in the report file and continues the operation on other objects. Information about successfully processed objects is not recorded in the report file. |
|
--snapshot-path |
If you specify this option, a snapshot is generated only for the objects in the current operation. If a snapshot already exists for an object, the operation is skipped for that object. Note
This option must be used with the -r, --recursive or --object-file option. |
|
--disable-ignore-error |
Does not ignore errors during batch operations. |
|
--version-id |
The version ID of the object. This option applies only to objects in buckets for which versioning is enabled or suspended. |
|
--include |
Includes all objects that meet the specified condition. For more information, see The --include and --exclude options. |
|
--exclude |
No Objects meet the specified conditions. For more information, see The --include and --exclude options. |
Set or update metadata
In the following examples that do not include the --update option, if you do not specify the header:value#header:value... option, only user-defined metadata that starts with X-Oss-Meta- is retained, and its values are not changed. For HTTP headers, ossutil enters an interactive mode and prompts you to confirm whether to retain them.
-
Example 1: Set or update metadata for a single object
-
Set the access control list (ACL) of exampleobject.txt in the examplebucket bucket to private.
ossutil set-meta oss://examplebucket/exampleobject.txt X-Oss-Object-Acl:private -
Set the storage class of a specific version of the exampleobject.txt object in the examplebucket bucket to Standard.
ossutil set-meta oss://examplebucket/exampleobject.txt X-Oss-Storage-Class:Standard --version-id CAEQARiBgID8rumR2hYiIGUyOTAyZGY2MzU5MjQ5ZjlhYzQzZjNlYTAyZDE3MDRk -
Set the storage class of a specific version of the exampleobject.txt object in the examplebucket bucket to Cold Archive.
ossutil set-meta oss://examplebucket/exampleobject.txt X-Oss-Storage-Class:ColdArchive --version-id CAEQARiBgID8rumR2hYiIGUyOTAyZGY2MzU5MjQ5ZjlhYzQzZjNlYTAyZDE3MDRkNoteThe storage class is not changed during the execution of the set-meta command. The change takes effect after the command completes.
For more information about how to obtain object versions, see ls.
-
Update the ACL of the exampleobject.txt object in the examplebucket bucket to public-read.
ossutil set-meta oss://examplebucket/exampleobject.txt X-Oss-Object-Acl:public-read --updateWhen you use the --update option, only the metadata for the specified headers is updated. The values of these headers are replaced, and all other existing metadata on the object remains unchanged. For example, the command updates only the ACL of the exampleobject.txt object to public-read. All other metadata of the object is preserved.
-
-
Example 2: Set or update metadata for multiple objects in the same folder in a batch operation
When you set or modify metadata for multiple objects in a batch operation, if an error occurs for an object, ossutil records the error message for that object in a report file in the ossutil_output folder. Successfully processed objects are not recorded in the report file.
-
Set metadata for objects that match a specified prefix
Use the -r option to change the caching behavior (Cache-Control) to no-cache and the ACL (x-oss-object-acl) to private for all objects that match the `src` prefix in the examplebucket bucket.
ossutil set-meta oss://examplebucket/src Cache-Control:no-cache#X-Oss-Object-Acl:private -r -
Modify metadata for objects that match specified filter conditions
-
Use the -r and -u options to change the storage class to Infrequent Access (IA) for all objects of the .jpg file type in the desfolder/ folder of the examplebucket bucket.
ossutil set-meta oss://examplebucket/desfolder/ X-Oss-Storage-Class:IA --include "*.jpg" -u -r -
Use the -r and -u options to change the storage class to Archive Storage for objects in the desfolder/ folder of the examplebucket bucket if their filenames contain abc and their file types are not .jpg or .txt.
ossutil set-meta oss://examplebucket/desfolder/ X-Oss-Storage-Class:Archive --include "*abc*" --exclude "*.jpg" --exclude "*.txt" -u -r
ImportantWhen you use the set-meta command to change the storage class of a Cold Archive or Deep Cold Archive object larger than 100 MB, the operation may fail due to a server timeout. To change the storage class of these objects, use the cp command.
-
-
-
Example 3: Set or update metadata for multiple objects in the same or different folders
-
Objects in different folders
To set or update metadata for multiple objects located in different folders within a bucket, follow these steps. For example, exampleobject1.jpg is in the root folder of examplebucket, exampleobject2.png is in the dir1/ folder, and exampleobject3.txt is in the dir2/ folder.
-
You can write multiple Objects to a local file named localfile.txt to set or update their metadata.
exampleobject1.jpg dir1/exampleobject2.png dir2/exampleobject3.txt -
Set or update the metadata for the specified objects.
Use the --object-file option to change the caching behavior (Cache-Control) to no-cache and the ACL (x-oss-object-acl) to private for multiple objects in the examplebucket bucket, and enable snapshots.
ossutil set-meta oss://examplebucket Cache-Control:no-cache#X-Oss-Object-Acl:private --update --object-file localfile.txt --snapshot-path dir/
-
-
Objects in the same folder
-
Method 1
Refer to the preceding example for objects in different folders to set or update metadata for multiple objects in the same folder.
-
Method 2
Refer to Example 2 to set or update metadata for multiple objects in the same folder.
-
-
-
Sample output
If the operation is successful, the output shows the time elapsed. The following is a sample output:
0.106852(s) elapsed
Delete custom metadata
The --delete option deletes only custom metadata that starts with X-Oss-Meta-.
-
Example 1: Delete the custom metadata of a single object
Delete the custom metadata that starts with
X-Oss-Meta-for the exampleobject.txt object in the examplebucket bucket. The header value must be empty.ossutil set-meta oss://examplebucket/exampleobject.txt X-Oss-Meta-Createdby --delete -
Example 2: Delete the custom metadata of multiple objects in a batch operation
To delete the custom metadata of multiple objects in a batch operation, follow these steps:
-
Write the names of the objects whose custom metadata you want to delete to a local file named localfile.txt.
exampleobject1.jpg dir1/exampleobject2.png dir2/exampleobject3.txt -
Delete the custom metadata of the objects.
Use the --object-file option to delete the custom metadata that starts with
X-Oss-Meta-for multiple objects in the examplebucket bucket in a batch operation. The header value must be empty.ossutil set-meta oss://examplebucket X-Oss-Meta-Location --delete --object-file localfile.txt --snapshot-path dir/
-
-
Sample output
If the operation is successful, the output shows the time elapsed. The following is a sample output:
0.106846(s) elapsed
Common options
To access a bucket in a different region, use -e to specify the endpoint. To access a bucket owned by a different Alibaba Cloud account, use -i for the AccessKey ID and -k for the AccessKey secret.
For example, run the following command to set the ACL of the testobject.jpg object to private. The object is in the testbucket bucket, which is in the China (Shanghai) region and belongs to a different Alibaba Cloud account.
ossutil set-meta oss://testbucket/testobject.jpg X-Oss-Object-Acl:private -e oss-cn-shanghai.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecret