更新时间:2026-09-28 GMT+08:00
获取桶归档存储对象直读策略
功能说明
获取桶的归档存储对象直读策略。
接口约束
- 您必须是桶拥有者或拥有获取桶归档存储对象直读策略的权限,才能获取桶归档存储对象直读策略。建议使用IAM或桶策略进行授权,如果使用IAM则需授予obs:bucket:GetDirectColdAccessConfiguration权限,如果使用桶策略则需授予GetDirectColdAccessConfiguration权限。相关授权方式介绍可参见OBS权限控制概述,配置方式详见使用IAM自定义策略、自定义创建桶策略。
- OBS支持的region以及region与endPoint的对应关系,详细信息请参见地区与终端节点。
方法定义
ObsClient.getBucketDirectColdAccess(params)
请求参数说明
| 参数名称 | 参数类型 | 是否必选 | 描述 |
|---|---|---|---|
| Bucket | String | 必选 | 参数解释: 桶名。 约束限制:
默认取值: 无 |
返回结果说明
| 参数名称 | 参数类型 | 描述 |
| Status | number | 参数解释: OBS服务端返回的HTTP状态码。 取值范围: 状态码是一组从2xx(成功)到4xx或5xx(错误)的数字代码,状态码表示了请求响应的状态。完整的状态码列表请参见状态码。 |
| Code | string | 参数解释: OBS服务端返回的错误码。 |
| Message | string | 参数解释: OBS服务端返回的错误描述。 |
| HostId | string | 参数解释: OBS服务端返回的请求服务端ID。 |
| RequestId | string | 参数解释: OBS服务端返回的请求ID。 |
| Id2 | string | 参数解释: OBS服务端返回的请求ID2。 |
| Indicator | string | 参数解释: OBS服务端返回的详细错误码。 |
| 参数名称 | 参数类型 | 描述 |
|---|---|---|
| Status | String | 参数解释: 桶的归档存储对象直读策略。 取值范围:
|
代码示例
本示例用于获取名为examplebucket的桶归档存储对象直读策略。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量AccessKeyID和SecretAccessKey。 // 前端本身没有process对象,可以使用webpack类打包工具定义环境变量,就可以在代码中运行了。 // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html const AK = process.env.AccessKeyID const SK = process.env.SecretAccessKey // 【可选】如果使用临时AKSK和SecurityToken访问OBS,则同样推荐通过环境变量获取 const security_token= process.env.SecurityToken // server填写Bucket对应的Endpoint, 这里以中国-香港为例,其他地区请按实际情况填写。 const server = "https://obs.ap-southeast-1.myhuaweicloud.com" // 创建ObsClient实例 var obsClient = new ObsClient({ access_key_id: AK, secret_access_key: SK, server: server }); async function getBucketDirectColdAccess() { try { const params = { Bucket: 'examplebucket', }; // 获取桶归档存储对象直读策略 const result = await obsClient.getBucketDirectColdAccess(params); if (result.CommonMsg.Status < 300) { console.log("Get bucket(%s)'s DirectColdAccess successful!", params.Bucket); console.log("RequestId: %s", result.CommonMsg.RequestId); console.log("Status: %s", result.InterfaceResult.Status); return; }; console.log("An ObsError was found, which means your request sent to OBS was rejected with an error response."); console.log("Status: %d", result.CommonMsg.Status); console.log("Code: %s", result.CommonMsg.Code); console.log("Message: %s", result.CommonMsg.Message); console.log("RequestId: %s", result.CommonMsg.RequestId); } catch (error) { console.log("An Exception was found, which means the client encountered an internal problem when attempting to communicate with OBS, for example, the client was unable to access the network."); console.log(error); }; }; getBucketDirectColdAccess(); |
父主题: 归档直读