最近更新时间:2021-11-01 20:45:56
以下代码用来获取对象的访问控制列表(ACL):
client.getObjectACL("<bucketName>", "<objectKey>", new GetObjectACLResponseHandler() {
@Override
public void onSuccess(int statesCode, Header[] responceHeaders, AccessControlPolicy accessControlPolicy) {
// 请求成功 返回accessControlPolicy对象
Owner owner = accessControlPolicy.getOwner();
HashSet<Grant> grants = accessControlPolicy.getAccessControlList().getGrants();
for (Grant grant : grants) {
// grant.getGrantee().getIdentifier()
// grant.getPermission()
}
}
@Override
public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
//请求异常
}
});
以下代码用来写入对象的访问控制列表(ACL):
PutObjectACLRequest request = new PutObjectACLRequest("<bucketName>", "<objectKey>");
// 使用封装好的权限对象
CannedAccessControlList cannedList = CannedAccessControlList.PublicRead;
// 当然也可以自行配置相关参数
// AccessControlList acList = new AccessControlList();
// request.setAccessControlList(acList);
request.setCannedAcl(cannedList);
client.putObjectACL(request, new PutObjectACLResponseHandler() {
@Override
public void onSuccess(int statesCode, Header[] responceHeaders) {
//请求成功
}
@Override
public void onFailure(int statesCode, Ks3Error error, Header[] responceHeaders, String response, Throwable paramThrowable) {
//请求异常
}
});
纯净模式