You need to enable JavaScript to run this app.
Torch Object Storage

Torch Object Storage

Copy page
Download PDF
Bucket Interface
Listing Buckets (Android SDK)
Copy page
Download PDF
Listing Buckets (Android SDK)
A bucket is a container for storing objects. You can obtain the list of storage buckets (Bucket) by using listBuckets; this operation returns all buckets.​
Precautions​
  • Before listing buckets, you must have the tos:ListBuckets permission. For detailed instructions, please refer to the Permission Configuration Guide.​
  • This interface returns all buckets across all regions for the current account.​
Sample Code​
The following code demonstrates how to enumerate all buckets.​
​
​
import android.os.Bundle;​
import android.util.Log;​
​
import androidx.appcompat.app.AppCompatActivity;​
​
import com.volcengine.tos.TOSV2;​
import com.volcengine.tos.TOSV2ClientBuilder;​
import com.volcengine.tos.TosException;​
import com.volcengine.tos.model.bucket.ListBucketsV2Input;​
import com.volcengine.tos.model.bucket.ListBucketsV2Output;​
import com.volcengine.tos.model.bucket.ListedBucket;​
​
public class ListBucketExample extends AppCompatActivity {​
​
@Override​
protected void onCreate(Bundle savedInstanceState) {​
String endpoint = "your endpoint";​
String region = "your region";​
String accessKey = "your access key";​
String secretKey = "your secret key";​
String securityToken = "your security token";​
​
String bucketName = "your bucket name";​
super.onCreate(savedInstanceState);​
setContentView(R.layout.activity_display_message);​
TOSV2 tos = new TOSV2ClientBuilder().build(region, endpoint, accessKey, secretKey, securityToken);​
​
Thread tosThread = new Thread(new Runnable() {​
@Override​
public void run() {​
try{​
ListBucketsV2Input input = new ListBucketsV2Input();​
ListBucketsV2Output output = tos.listBuckets(input);​
Log.i("listBuckets", "bucket owner is " + output.getOwner());​
if (output.getBuckets() != null) {​
Log.i("listBuckets", "you have listed " + output.getBuckets().size() + " buckets");​
for (int i = 0; i < output.getBuckets().size(); i++){​
ListedBucket bucket = output.getBuckets().get(i);​
Log.i("listBuckets", "the No." + " bucket is " + bucket.toString());​
}​
} else {​
Log.i("listBuckets", "there are no buckets in your account.");​
}​
} catch (TosException e) {​
Log.e("TosException", "listBuckets failed");​
e.printStackTrace();​
}​
}​
});​
​
tosThread.start();​
}​
}​
​
Relevant Documentation​
For documentation on the API for listing buckets, see ListBuckets.​
Last updated: 2025.09.25 14:23:26