Setting or Obtaining a Versioning Object ACL
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference.
Directly Setting a Versioning Object ACL
You can call ObsClient.setObjectAcl and use the VersionId parameter to specify the ACL for a versioning object. Sample code is as follows:
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'https://your-endpoint'
});
obsClient.setObjectAcl({
Bucket : 'bucketname',
Key : 'objectname',
VersionId : 'versionid',
// Set the versioning object ACL to public-read by specifying the pre-defined access control policy.
ACL : obsClient.enums.AclPublicRead
}, function (err, result) {
if(err){
console.log('Error-->' + err);
}else{
console.log('Status-->' + result.CommonMsg.Status);
}
});
obsClient.setObjectAcl({
Bucket : 'bucketname',
Key : 'objectname',
VersionId : 'versionid',
// Set the object owner.
Owner:{'ID':'ownerid'},
Grants:[
// Grant the READ and WRITE_ACP permission to all users.
{ Grantee:{Type : 'Group', URI : obsClient.enums.GroupAllUsers}, Permission : obsClient.enums.PermissionRead},
{ Grantee:{Type : 'Group', URI : obsClient.enums.GroupAllUsers}, Permission : obsClient.enums.PermissionWriteAcp}
]
}, function (err, result) {
if(err){
console.log('Error-->' + err);
}else{
console.log('Status-->' + result.CommonMsg.Status);
}
});
- Use the Owner parameter to specify the object owner and the Grants parameter to specify information about the authorized users.
- The owner or grantee ID needed in the ACL indicates the account ID, which can be viewed on the My Credential page of OBS Console.
- OBS buckets support the following grantee group:
- All users: ObsClient.enums.GroupAllUsers
Obtaining a Versioning Object ACL
You can call ObsClient.getObjectAcl and specify the VersionId parameter to obtain the ACL of a versioning object. Sample code is as follows:
// Create an instance of ObsClient.
var obsClient = new ObsClient({
access_key_id: '*** Provide your Access Key ***',
secret_access_key: '*** Provide your Secret Key ***',
server : 'https://your-endpoint'
});
obsClient.getObjectAcl({
Bucket : 'bucketname',
Key : 'objectname',
VersionId : 'versionid'
}, function (err, result) {
if(err){
console.log('Error-->' + err);
}else{
console.log('Status-->' + result.CommonMsg.Status);
if(result.CommonMsg.Status < 300 && result.InterfaceResult){
console.log('Owner[ID]-->' + result.InterfaceResult.Owner.ID);
console.log('Owner[Name]-->' + result.InterfaceResult.Owner.Name);
for(var i in result.InterfaceResult.Grants){
console.log('Grant[' + i + ']:');
console.log('Grantee[ID]-->' + result.InterfaceResult.Grants[i]['Grantee']['ID']);
console.log('Grantee[URI]-->' + result.InterfaceResult.Grants[i]['Grantee']['URI']);
console.log('Permission-->'+ result.InterfaceResult.Grants[i]['Permission']);
}
}
}
});
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.