• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Android 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 bukets.
ListBucketsRequest request = new ListBucketsRequest();
request.setQueryLocation(true)
List<ObsBucket> buckets = obsClient.listBuckets(request);
for(ObsBucket bucket : buckets){
    Log.i("ListBuckets", "BucketName" + bucket.getBucketName());
    Log.i("ListBuckets", "CreationDate" + bucket.getCreationDate());
    Log.i("ListBuckets", "Location:" + bucket.getLocation());
}
// Close obsClient.
obsClient.close();
NOTE:
  • Obtained bucket names are listed in the lexicographical order.
  • Set ListBucketsRequest.setQueryLocation to query the bucket location when listing buckets.