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

Torch Object Storage

Copy page
Download PDF
Bucket Interface
Creating a Bucket (Android SDK)
Copy page
Download PDF
Creating a Bucket (Android SDK)
A Bucket is the globally unique namespace in TOS, functioning as a data container used to store Object data. The name of a newly created bucket must be unique within TOS.​
Precautions​
  • Only lowercase letters a–z, digits, and hyphens (-) are permitted.​
  • The first and last character must be a digit or a letter.​
  • The length must be between 3 and 63 characters.​
  • When accessing TOS from other Volcano Engine products within the same region, it is recommended to use the intranet endpoint. For more information about regions and Endpoints, see Regions and Access Domains.​
  • Before creating a storage bucket, you must ensure that your account has the tos:CreateBucket permission. You can grant the corresponding permissions through IAM policies. For detailed steps, see IAM policies.​
Sample Code​
The following code demonstrates how to create a new bucket.​
​
​
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.comm.common.ACLType;​
import com.volcengine.tos.comm.common.StorageClassType;​
import com.volcengine.tos.model.bucket.CreateBucketV2Input;​
import com.volcengine.tos.model.bucket.CreateBucketV2Output;​
​
public class CreateBucketFullExample 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";​
​
ACLType aclType = ACLType.ACL_PRIVATE;​
​
StorageClassType storageClassType = StorageClassType.STORAGE_CLASS_STANDARD;​
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 {​
CreateBucketV2Input input = new CreateBucketV2Input().setBucket(bucketName)​
.setAcl(aclType).setStorageClass(storageClassType);​
CreateBucketV2Output output = tos.createBucket(input);​
Log.i("createBucket", output.getLocation());​
} catch (TosException e) {​
Log.e("TosException", "createBucket failed");​
e.printStackTrace();​
}​
}​
});​
​
tosThread.start();​
}​
}​
​
Relevant Documentation​
For API documentation on creating buckets, refer to CreateBucket.​
Last updated: 2025.09.25 14:23:26