Setting or Obtaining a Versioning Object ACL
Directly Setting a Versioning Object ACL
You can call OBSSetObjectACLRequest to input the version ID (versionID) to set the ACL for a versioning object. 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 access control policy for a versioning object.
OBSUser *owner = [[OBSUser alloc] initWithID:@"249e6c2bfbc74c928d5893895543029e"];
OBSACLGranteeUser *grantee = [[OBSACLGranteeUser alloc]initWithID:@"AKjdsjklSKLL/DSKDSLADLADLjdsjald231124"];
// Grant the FULL_CONTROL permission to authorized users.
OBSACLGrant *grant = [[OBSACLGrant alloc]initWithGrantee:grantee permission:OBSACLFull_Control];
OBSAccessControlPolicy *policy = [OBSAccessControlPolicy new];
policy.owner = owner;
[policy.accessControlList addObject:grant];
for(int i=0;i<=20;i++){
[policy.accessControlList addObject:grant];
}
OBSSetObjectACLRequest *request = [[OBSSetObjectACLRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname" accessControlPolicy:policy];
request.versionID = @"Version ID of a versioning object";
[client setObjectACL:request completionHandler:^(OBSSetObjectACLResponse *response, NSError *error){
NSLog(@"%@",response);
}];
The owner or grantee ID needed in the ACL indicates the account ID, which can be viewed on the My Credentials page of OBS Console.
Obtaining a Versioning Object ACL
You can call OBSGetObjectACLRequest to pass the version ID (versionID) to obtain the ACL for a versioning object. 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 access control policy of a versioning object.
OBSGetObjectACLRequest *request = [[OBSGetObjectACLRequest alloc]initWithBucketName:@"bucketname" objectKey:@"objectname"];
// Set the version ID for a versioning object.
request.versionID = @"Version ID of a versioning object";
[client getObjectACL:request completionHandler:^(OBSGetObjectACLResponse *response, NSError *error){
NSLog(@"%@",response);
}]; Last Article: Listing Versioning Objects
Next Article: Deleting Versioning Objects
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.