tencent cloud

All product documents
Cloud Object Storage
Bucket policy
Last updated: 2024-01-23 17:15:08
Bucket policy
Last updated: 2024-01-23 17:15:08

Overview

This document provides an overview of APIs and SDK code samples related to bucket policies.
API
Operation
Description
Setting a bucket policy
Sets a permission policy for the specified bucket
Querying bucket policy
Queries the permission policy of the specified bucket
Deleting bucket policies
Deletes the permission policies of a specified bucket

SDK API References

For the parameters and method descriptions of all the APIs in the SDK, please see SDK API Reference.

Setting a bucket policy

Feature description

This API is used to set an access policy on a bucket.
Note:
The COS iOS SDK version should be v6.1.8 or higher.

Sample code

QCloudPutBucketPolicyRequest * request = [QCloudPutBucketPolicyRequest new];
// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.
request.bucket = @"0-1250000000";
request.regionName = @"ap-chengdu";
// Permission policy. For more information, see [CAM Practices > Policy Syntax](https://www.tencentcloud.com/document/product/436/12469).
request.policyInfo = @{
@"Statement": @[
@{
@"Principal": @{
@"qcs": @[
@"qcs::cam::uin/100000000001:uin/100000000001"
]
},
@"Effect": @"allow",
@"Action": @[
@"name/cos:GetBucket"
],
@"Resource": @[
@"qcs::cos:ap-guangzhou:uid/1250000000:examplebucket-1250000000/*"
]
}
],
@"version": @"2.0"
};
[request setFinishBlock:^(id _Nullable outputObject, NSError * _Nullable error) {

}];
[[QCloudCOSXMLService defaultCOSXML] PutBucketPolicy:request];
Note:
For the complete sample, go to GitHub.

Querying a bucket policy

Feature description

This API is used to query the access policy on a bucket.
Note:
The COS Android SDK version should not be earlier than v6.1.8.

Sample code


QCloudGetBucketPolicyRequest * request = [QCloudGetBucketPolicyRequest new];
// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.
request.bucket = @"bucketname-appid";
request.regionName = @"ap-chengdu";
[request setFinishBlock:^(QCloudBucketPolicyResult * _Nullable outputObject, NSError * _Nullable error) {
// For detailed fields in `QCloudBucketPolicyResult`, see the API documentation or SDK source code.
}];
[[QCloudCOSXMLService defaultCOSXML] GetBucketPolicy:request];
Note:
For the complete sample, go to GitHub.

Deleting a bucket policy

Feature description

This API is used to delete the access policy from a specified bucket.
Note:
The COS Android SDK version should not be earlier than v6.1.8.

Sample code

// Bucket name in the format of `BucketName-APPID` (`APPID` is required), which can be viewed in the COS console at https://console.cloud.tencent.com/cos5/bucket.
QCloudDeleteBucketPolicyRequest * request = [QCloudDeleteBucketPolicyRequest new];
request.bucket = @"0-1253960454";
request.regionName = @"ap-chengdu";
[request setFinishBlock:^(id _Nullable outputObject, NSError * _Nullable error) {
/// If `error` is null, the request is successful.
}];
[[QCloudCOSXMLService defaultCOSXML] DeleteBucketPolicy:request];
Note:
For the complete sample, go to GitHub.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon