• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Java SDK)
  4. Bucket Management
  5. Listing Buckets

Listing Buckets

You can call ObsClient.listBuckets to list buckets. Sample code is as follows:

String endPoint = "yourdomainname";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

// List buckets.
ListBucketsRequest request = new ListBucketsRequest();
request.setQueryLocation(true)
List<ObsBucket> buckets = obsClient.listBuckets(request);
for(ObsBucket bucket : buckets){
    System.out.println("BucketName:" + bucket.getBucketName());
    System.out.println("CreationDate:" + bucket.getCreationDate());
    System.out.println("Location:" + bucket.getLocation());
}
// Close obsClient.
obsClient.close();
NOTE:
  • Obtained bucket names are listed in the lexicographical order.
  • Set ListBucketsRequest.setQueryLocation to true and then you can query the bucket location when listing buckets.