API | Operation | Description |
Querying the bucket list | Queries the list of all buckets under a specified account | |
Creating a bucket | Creates a bucket under a specified account | |
Checking a bucket and its permissions | Checks whether a bucket exists and whether you have permission to access it | |
Deleting a bucket | Deletes an empty bucket under a specified account |
public List<Bucket> listBuckets() throws CosClientException, CosServiceException;
// If you only call the “listBuckets” method, set the region to new Region("") when creating cosClient.List<Bucket> buckets = cosClient.listBuckets();for (Bucket bucketElement : buckets) {String bucketName = bucketElement.getName();String bucketLocation = bucketElement.getLocation();}
public Bucket createBucket(String bucketName) throws CosClientException, CosServiceException;
String bucket = "examplebucket-1250000000"; // Bucket, formatted as BucketName-APPIDCreateBucketRequest createBucketRequest = new CreateBucketRequest(bucket);// Set the bucket permission to Private (private read/write). Other options include public read/private write and public read/write.createBucketRequest.setCannedAcl(CannedAccessControlList.Private);Bucket bucketResult = cosClient.createBucket(createBucketRequest);
Parameter | Description | Type |
bucketName | String |
public boolean doesBucketExist(String bucketName)throws CosClientException, CosServiceException;
The bucket name entered must be in the format of `BucketName-APPID`.String bucketName = "examplebucket-1250000000";boolean bucketExistFlag = cosClient.doesBucketExist(bucketName);
Parameter | Description | Type |
bucketName | String |
true
if the bucket exists. Otherwise, false
is returned.CosClientException
or CosServiceException
exception will be reported. For more information, see Troubleshooting.public void deleteBucket(String bucketName) throws CosClientException, CosServiceException;
The bucket name entered must be in the format of `BucketName-APPID`.String bucketName = "examplebucket-1250000000";cosClient.deleteBucket(bucketName);
Parameter | Description | Type |
bucketName | String |
CosClientException
or CosServiceException
exception will be reported. For more information, see Troubleshooting.
Was this page helpful?