All Products
Search
Document Center

Object Storage Service:Create buckets (Android SDK)

Last Updated:Feb 28, 2026

A bucket is a container for storing objects. All objects must be stored in a bucket. This topic describes how to create a bucket.

Prerequisites

You have initialized an OSSClient instance by using a method such as a custom domain name or Security Token Service (STS). For more information, see Initialize an OSSClient instance for Android.

Usage notes

From 10:00 (UTC+8) on October 13, 2025, OSS will implement a phased adjustment across all regions to enable Block Public Access by default for new buckets created using the API, OSS SDKs, or ossutil. For details about the exact times when the adjustment will take effect in each region, see [Official Announcement] Adjustment to the Public Access Blocking Configurations for Newly Created Buckets.

Once Block Public Access is enabled:

  • You cannot configure public access permissions, including public ACLs (public read and public read/write) and bucket policies that allow public access.

  • You can disable this feature after the bucket is created if your business requires public access.

Required permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket policies.

The following table lists the API operation and the required permissions.

API Action Description
PutBucket oss:PutBucket Creates a bucket.
oss:PutBucketAcl After creating a bucket, this permission is required to modify the bucket ACL.

Sample code

The following code shows how to create a bucket named examplebucket.

Note

The region of the bucket is determined by the region of the endpoint that you specify during initialization.

// Construct a request to create a bucket.
// Specify the bucket name.
CreateBucketRequest createBucketRequest = new CreateBucketRequest("examplebucket");

// Specify the access control list (ACL) of the bucket.
// createBucketRequest.setBucketACL(CannedAccessControlList.Private);

// Specify the storage class of the bucket.
// createBucketRequest.setBucketStorageClass(StorageClass.Standard);

// Create the bucket asynchronously.
OSSAsyncTask createTask = oss.asyncCreateBucket(createBucketRequest, new OSSCompletedCallback<CreateBucketRequest, CreateBucketResult>() {
    @Override
    public void onSuccess(CreateBucketRequest request, CreateBucketResult result) {
        Log.d("asyncCreateBucket", "Success");
    }

    @Override
    public void onFailure(CreateBucketRequest request, ClientException clientException, ServiceException serviceException) {
        // Request exception.
        if (clientException != null) {
            // Client-side exceptions, such as network errors.
            clientException.printStackTrace();
        }
        if (serviceException != null) {
            // Server-side exceptions.
            Log.e("ErrorCode", serviceException.getErrorCode());
            Log.e("RequestId", serviceException.getRequestId());
            Log.e("HostId", serviceException.getHostId());
            Log.e("RawMessage", serviceException.getRawMessage());
        }
    }
});

References