Creating a Bucket
You can call createBucket to create a bucket.
Creating a Bucket in Simple Mode
Sample code:
static OBSClient *client;
NSString *endPoint = @"your-endpoint";
NSString *SK = @"*** Provide your Secret Key ***";
NSString *AK = @"*** Provide your Access Key ***";
// Initialize identity authentication.
OBSStaticCredentialProvider *credentialProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
//Initialize service configuration.
OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
// Initialize an instance of OBSClient.
client = [[OBSClient alloc] initWithConfiguration:conf];
//Make a request for creating a bucket.
OBSCreateBucketRequest *request = [[OBSCreateBucketRequest alloc] initWithBucketName:@"bucketname"];
//Create a bucket.
[client createBucket:request completionHandler:^(OBSCreateBucketResponse *response, NSError *error) {
NSLog(@"%@",response.location);
}];
- Bucket names are globally unique. Ensure that the bucket you create is named differently from any other bucket.
- A bucket name must comply with the following rules:
- Contains 3 to 63 characters, starts with a digit or letter, and supports only lowercase letters, digits, hyphens (-), and periods (.)
- Cannot be an IP address.
- Cannot start or end with a hyphen (-) or period (.).
- Cannot contain two consecutive periods (.), for example, my..bucket.
- Cannot contain periods (.) and hyphens (-) adjacent to each other, for example, my-.bucket or my.-bucket.
- If you create buckets of the same name in a region, no error will be reported and the bucket properties comply with those set in the first creation request.
- In this example, the bucket is of the default ACL (public-read-write), in the OBS Standard storage class, and in the default location where the global domain resides.
- This parameter is not required if the endpoint belongs to the default region (cn-north-1). Otherwise, set this parameter to the region to which the endpoint belongs. Click here to query currently valid regions.
- When creating a bucket, you can specify its region. For details, see Creating a Bucket with Parameters Specified.
Creating a Bucket with Parameters Specified
static OBSClient *client;
NSString *endPoint = @"your-endpoint";
NSString *SK = @"*** Provide your Secret Key ***";
NSString *AK = @"*** Provide your Access Key ***";
// Initialize identity authentication.
OBSStaticCredentialProvider *credentialProvider = [[OBSStaticCredentialProvider alloc] initWithAccessKey:AK secretKey:SK];
//Initialize service configuration.
OBSServiceConfiguration *conf = [[OBSServiceConfiguration alloc] initWithURLString:endPoint credentialProvider:credentialProvider];
// Initialize an instance of OBSClient.
client = [[OBSClient alloc] initWithConfiguration:conf];
//Create a bucket.
OBSCreateBucketRequest *request = [[OBSCreateBucketRequest alloc] initWithBucketName:@"bucketname"];
// Set the access control policy to public-read-write.
request.bucketACLPolicy = OBSACLPolicyPublicReadWrite;
// Set the storage class to OBS Standard.
request.defaultStorageClass = OBSStorageClassStandard;
// Set the bucket location.
request.configuration = [[OBSBucketConfiguration alloc] initWithLocationConstraint:@"bucketlocation"];
[client createBucket:request completionHandler:^(OBSCreateBucketResponse *response, NSError *error) {
NSLog(@"%@",response.location);
}]; Last Article: Bucket Management
Next Article: Listing Buckets
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.