文档

获取云盒Bucket信息

更新时间:

您可以通过GetBucketInfo接口查看云盒Bucket的信息,包括云盒Bucket的创建时间、读写权限、拥有者信息等。

前提条件

  • 华东1(杭州)、华南1(深圳)、华南2(河源)、华北2(北京)、西南1(成都)地域支持使用OSS ON云盒服务。

  • 已购买云盒。具体操作,请参见购买云盒

操作步骤

使用OSS控制台

  1. 登录OSS管理控制台

  2. 在左侧导航栏,选择数据服务 > 云盒Bucket,然后在Bucket列表中单击目标Bucket。

  3. 概览页,查看云盒Bucket访问域名、基础设置等信息。

使用阿里云SDK

仅支持通过Java SDK获取云盒Bucket信息,Java SDK要求3.15.0及以上版本。

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.BucketInfo;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;

public class Demo {

    public static void main(String[] args) throws Exception {
        // 填写云盒Bucket的数据域名。
        String endpoint = "https://cb-f8z7yvzgwfkl9q0h****.cn-hangzhou.oss-cloudbox.aliyuncs.com";
        // 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // 填写云盒Bucket名称,例如examplebucket。
        String bucketName = "examplebucket";
        // 填写云盒Bucket所在地域。
        String region = "cn-hangzhou";
        // 填写云盒ID。
        String cloudBoxId = "cb-f8z7yvzgwfkl9q0h****";

        // 创建OSSClient实例。
        ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
        conf.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(new DefaultCredentialProvider(credentialsProvider.getCredentials()))
                .clientConfiguration(conf)
                .region(region)
                .cloudBoxId(cloudBoxId)
                .build();

        try {
            // 获取地域信息。
            info.getBucket().getLocation();
            // 获取创建日期。
            info.getBucket().getCreationDate();
            // 获取拥有者信息。
            info.getBucket().getOwner();
            // 获取读写权限。
            info.getCannedACL().toString();
            // 获取存储类型。
            info.getBucket().getStorageClass();
            // 获取版本控制状态。
            info.getBucket().getVersioning();            
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

使用命令行工具ossutil

关于使用ossutil获取云盒Bucket信息的具体步骤,请参见stat

使用REST API

如果您的程序自定义要求较高,您可以直接发起REST API请求。直接发起REST API请求需要手动编写代码计算签名。更多信息,请参见GetBucketInfo

  • 本页导读 (1)
文档反馈