设置桶的生命周期配置
功能说明
配置桶的生命周期规则,实现定时删除桶中对象的功能。
方法定义
1. ObsClient->setBucketLifecycle(array $parameter) 2. ObsClient->setBucketLifecycleAsync(array $parameter, callable $callback)
请求参数
字段名 | 类型 | 约束 | 说明 | ||
|---|---|---|---|---|---|
Bucket | string | 必选 | 桶名。 | ||
Rules | indexed array | 必选 | 桶生命周期规则列表。 | ||
- | Transitions | indexed array | 可选 | 对象转换策略列表。 | |
- | StorageClass | string | 必选 | 对象转换后的存储类型。 说明: 不支持“标准存储”类型。 | |
Date | string 或 \DateTime | 如果没有设置Days则必选 | 表示对象转换的日期。该值必须兼容ISO8601格式(例如:2018-01-01T00:00:00Z),而且必须是UTC午夜0点。 | ||
Days | integer | 如果没有设置Date则必选 | 表示在对象创建时间后第几天时转换,正整数。 | ||
- | Expiration | associative array | 可选 | 对象过期时间配置。 | |
- | Date | string 或 \DateTime | 如果没有设置Days则必选 | 表示对象过期的日期。该值为字符串时必须兼容ISO8601格式(例如:2018-01-01T00:00:00Z),而且必须是UTC午夜0点。 | |
Days | integer | 如果没有设置Date则必选 | 表示在对象创建时间后第几天时过期,正整数。 | ||
ID | string | 可选 | 规则ID,由不超过255个字符的字符串组成。 | ||
Prefix | string | 必选 | 对象名前缀,用以标识哪些对象可以匹配到当前这条规则。可为空字符串,代表匹配桶内所有对象。 | ||
Status | string | 必选 | 标识当前这条规则是否启用,支持的值:
| ||
- | NoncurrentVersionTransitions | indexed array | 可选 | 历史版本对象转换策略列表。 | |
- | StorageClass | string | 必选 | 历史版本对象转换后的存储类型。 | |
NoncurrentDays | integer | 必选 | 表示对象成为历史版本后第几天时转换,正整数。 | ||
- | NoncurrentVersionExpiration | associative array | 可选 | 历史版本对象过期时间配置。 | |
- | NoncurrentDays | integer | 必选 | 表示对象成为历史版本后第几天时过期,正整数。 | |

Transitions、Expiration、NoncurrentVersionTransitions、NoncurrentVersionExpiration不能全为空。
返回结果
字段名 | 类型 | 说明 |
|---|---|---|
HttpStatusCode | integer | HTTP状态码。 |
Reason | string | HTTP文本描述。 |
RequestId | string | OBS服务端返回的请求ID。 |
代码样例
try{
$resp = $obsClient -> setBucketLifecycle([
'Bucket' => 'bucketname',
'Rules' => [
['ID' => 'rule1', 'Prefix' => 'prefix1', 'Status' => 'Enabled', 'Expiration' => ['Days' => 60], 'NoncurrentVersionExpiration' => ['NoncurrentDays' => 60]],
['ID' => 'rule2', 'Prefix' => 'prefix2', 'Status' => 'Enabled', 'Expiration' => ['Date' => '2018-12-31T00:00:00Z']]
]
]);
printf("RequestId:%s\n", $resp['RequestId']);
}catch (Obs\Common\ObsException $obsException){
printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
} 
