对象存储

产品文档

对象存储

存储空间

存储空间(Bucket)是存储对象(Object)的容器。

存储空间功能操作

创建存储空间


String bucket_name = "<yourBucketName>";
try {
    // 创建存储空间。
    s3.createBucket(bucket_name);
    System.out.format("creat OSS bucket %s...",  bucket_name);
} catch (AmazonServiceException e) {
    // 捕获异常。
    e.printStackTrace();
}

列出同一地域中Bucket


List<Bucket> buckets = s3.listBuckets();
System.out.println("Your jdcloud OSS buckets are:");
for (Bucket a : buckets) {
    System.out.println("* " + a.getName());
}

列举Bucket中文件(List Objects)


String bucket_name = "<your bucketname>";

System.out.format("Objects in OSS bucket %s:\n", bucket_name);
ListObjectsV2Result result = s3.listObjectsV2(bucket_name);
List<S3ObjectSummary> objects = result.getObjectSummaries();
for (S3ObjectSummary os: objects) {
    System.out.println("* " + os.getKey());
}

删除Bucket



String bucket_name = "<your bucketname>";

try {
    s3.deleteBucket(bucket_name);
} catch (AmazonServiceException e) {
    System.err.println(e.getErrorMessage());
    System.exit(1);
}

更新时间:2019-06-26 19:28:23
文档反馈 docs feedback