A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to delete a bucket.

  • Before you delete a bucket, you must delete all objects in the bucket, LiveChannel objects, and fragments generated by multipart uploads. For more information about deleting a LiveChannel object, see LiveChannel.
  • To delete the parts generated in multipart upload tasks, call ListMultipartUploads to list all the parts first, and call AbortMultipartUpload to delete the parts.

The following code provides an example on how to delete a bucket:

DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest("<bucketName>");

// Delete the bucket asynchronously.
OSSAsyncTask deleteBucketTask = oss.asyncDeleteBucket(deleteBucketRequest, new OSSCompletedCallback<DeleteBucketRequest, DeleteBucketResult>() {
    public void onSuccess(DeleteBucketRequest request, DeleteBucketResult result) {
        Log.d("asyncDeleteBucket", "Success!") ;
    public void onFailure(DeleteBucketRequest request, ClientException clientException, ServiceException serviceException) {
        // Handle request exceptions.
        if (clientException ! = null) {
            // Handle client exceptions, such as network exceptions.
        if (serviceException ! = null) {
            // Handle service exceptions.
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
  • To prevent unexpected data loss, OSS does not allow users to delete non-empty buckets.
  • You cannot recover deleted buckets. Exercise caution when you perform this operation.
  • For more information about how to delete a bucket, see DeleteBucket.