更新时间:2024-06-21 GMT+08:00
获取桶元数据
您可以通过ObsClient.getBucketMetadata接口获取桶元数据。以下代码展示如何获取桶元数据:
// 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;本示例以ak和sk保存在环境变量中为例,运行本示例前请先在本地环境中设置环境变量ACCESS_KEY_ID和SECRET_ACCESS_KEY_ID。 // 您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/intl/zh-cn/usermanual-ca/ca_01_0003.html String ak = System.getenv("ACCESS_KEY_ID"); String sk = System.getenv("SECRET_ACCESS_KEY_ID"); String endPoint = "https://your-endpoint"; // 创建ObsClient实例 ObsClient obsClient = new ObsClient(ak, sk, endPoint); BucketMetadataInfoRequest request = new BucketMetadataInfoRequest("bucketname"); request.setOrigin("http://www.a.com"); //获取桶元数据 BucketMetadataInfoResult result = obsClient.getBucketMetadata(request); Log.i("GetBucketMetadata", "\t:" + result.getDefaultStorageClass()); Log.i("GetBucketMetadata", "\t:" + result.getAllowOrigin()); Log.i("GetBucketMetadata", "\t:" + result.getMaxAge()); Log.i("GetBucketMetadata", "\t:" + result.getAllowHeaders()); Log.i("GetBucketMetadata", "\t:" + result.getAllowMethods()); Log.i("GetBucketMetadata", "\t:" + result.getExposeHeaders());
BucketMetadataInfoResult.getAllowMethods等方法的值参见桶的跨域资源共享(CORS)配置。
父主题: 管理桶