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

Torch Object Storage

Copy page
Download PDF
Bucket Interface
Deleting a Bucket (Android SDK)
Copy page
Download PDF
Deleting a Bucket (Android SDK)
You can use the deleteBucket interface to delete an empty bucket that does not contain any object data. For non-empty buckets, you must first remove all objects and incomplete multipart upload tasks from the bucket before invoking this interface to perform the delete bucket operation.​
Precautions​
  • Once a bucket is deleted, it cannot be restored. Please proceed with caution.​
  • Before deleting a bucket, you must have the tos:DeleteBucket permission. For specific operations, please refer to the Permission Configuration Guide.​
Prerequisites​
Before deleting a bucket, ensure that all data within the bucket has been deleted.​
  • If versioning is enabled for the bucket, please ensure that all current and previous version objects within the bucket have been deleted. For detailed procedures, please refer to Delete Object.​
  • If there are unmerged fragments in the bucket, please ensure that all fragment data is deleted. For specific instructions, see Delete Fragment.​
  • If your bucket contains a large number of objects, you can configure bulk deletion by applying lifecycle rules. For detailed instructions, please refer to Set Lifecycle Rules.​
Sample Code​
The following code demonstrates how to delete empty 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.DeleteBucketInput;​
import com.volcengine.tos.model.bucket.DeleteBucketOutput;​
​
public class DeleteBucketExample 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{​
DeleteBucketInput input = new DeleteBucketInput().setBucket(bucketName);​
DeleteBucketOutput output = tos.deleteBucket(input);​
Log.i("deleteBucket", "deleteBucket succeed, " + output);​
} catch (TosException e) {​
if (e.getStatusCode() == 404) {​
Log.e("TosException", "deleteBucket failed, the bucket is not found.");​
} else {​
Log.e("TosException", "deleteBucket failed.");​
}​
e.printStackTrace();​
}​
}​
});​
​
tosThread.start();​
}​
}​
​
Relevant Documentation​
For API documentation on deleting buckets, refer to DeleteBucket.​
Last updated: 2025.09.25 14:23:26