更新时间:2025-12-04 GMT+08:00
分享

设置对象标签

功能说明

为指定桶中的对象设置标签信息。

方法定义

ObsClient->setObjectTagging(array $parameter)

请求参数

字段名

类型

约束

说明

Bucket

string

必选

桶名。

Key

string

必选

目标对象名。

VersionId

string

可选

待删除对象的版本号。

Tags

indexed array

必选

桶标签列表。

-

Key

string

必选

标签的键名(Key)的最大长度为128个字符,可用UTF-8格式表示的字母(含中文)、数字、空格,以及以下字符:_ . : = + - @;区分大小写,不可重复,不能为空。

Value

string

必选

标签的键值(Value)的最大长度为255个字符,可用UTF-8格式表示的字母(含中文)、数字、空格,以及以下字符:_ . : /= + - @;区分大小写,可以为空。

  • 文件桶不支持该功能
  • 每个对象最多能设置10个标签。

返回结果

字段名

类型

说明

HttpStatusCode

integer

HTTP状态码。

Reason

string

HTTP文本描述。

RequestId

string

OBS服务端返回的请求ID。

代码样例

try{
       $resp = $obsClient -> setObjectTagging([
              'Bucket' => 'bucketname',
              'Key' => 'objectname',
              'Tags' => [
                     ['Key' => 'tag1', 'Value' => 'value1'],
                     ['Key' => 'tag2', 'Value' => 'value2']
              ]
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}

相关文档