Help Center> Object Storage Service> SDK Reference> iOS> Bucket Management> Setting or Obtaining a Bucket Quota

Setting or Obtaining a Bucket Quota

Setting a Bucket Quota

You can call setBucketQuota to set the bucket quota. Sample code is as follows:

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];
    
// Set the bucket quota.
OBSQuota *quota = [[OBSQuota alloc] initWithQuotaNumber:[NSNumber numberWithLongLong:1024*1024*1024]];
    
OBSSetBucketQuotaRequest *request = [[OBSSetBucketQuotaRequest alloc] initWithBucketName:@"bucketname" quota:quota];
[client setBucketQuota:request completionHandler:^(OBSSetBucketQuotaResponse *response, NSError *error) {
    NSLog(@"%@",response.statusCode);
}];

A bucket quota must be a non-negative integer expressed in bytes. The maximum value is 263 - 1.

Obtaining a Bucket Quota

You can call getBucketQuota to obtain a bucket quota. Sample code is as follows:

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];
    
// Obtain the bucket quota.
OBSGetBucketQuotaRequest *request = [[OBSGetBucketQuotaRequest alloc]initWithBucketName:@"bucketname"];
    
[client getBucketQuota:request completionHandler:^(OBSGetBucketQuotaResponse *response, NSError *error){
    NSLog(@"%@",response.quota);
}];