Managing Bucket Policies

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

Besides bucket ACLs, bucket owners can use bucket policies to centrally control access to buckets and objects in buckets.

For more information, see Bucket Policy.

Setting a Bucket Policy

You can call ObsClient.setBucketPolicy to set a bucket policy. Sample code is as follows:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);
obsClient.setBucketPolicy("bucketname", "your policy");

For details about the format (JSON character string) of bucket policies, see the Object Storage Service API Reference.

Obtaining a Bucket Policy

You can call ObsClient.getBucketPolicy to obtain a bucket policy. Sample code is as follows:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

String policy = obsClient.getBucketPolicy("bucketname");
Log.i("GetBucketPolicy","\t" + policy);

Deleting a Bucket Policy

You can call ObsClient.deleteBucketPolicy to delete a bucket policy. Sample code is as follows:

String endPoint = "https://your-endpoint";
String ak = "*** Provide your Access Key ***";
String sk = "*** Provide your Secret Key ***";
// Create an instance of ObsClient.
ObsClient obsClient = new ObsClient(ak, sk, endPoint);

obsClient.deleteBucketPolicy("bucketname");