有奖捉虫:云通信与企业服务文档专题,速来> HOT

简介

本文档提供关于存储桶、对象的访问控制列表(ACL)的相关 API 概览以及 SDK 示例代码。
存储桶 ACL
API
操作名
操作描述
设置存储桶 ACL
设置指定存储桶的访问权限控制列表(ACL)
查询存储桶 ACL
获取指定存储桶的访问权限控制列表(ACL)
对象 ACL
API
操作名
操作描述
设置对象 ACL
设置 Bucket 中某个 Object (文件/对象)的 ACL
查询对象 ACL
查询 Object(文件/对象)的 ACL

存储桶 ACL

设置存储桶 ACL

功能说明

设置指定存储桶的访问权限控制列表(ACL)。

方法原型

public Guzzle\\Service\\Resource\\Model putBucketAcl(array $args = array());

请求示例

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部,默认为http
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->putBucketAcl(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'ACL' => 'private',
'Grants' => array(
array(
'Grantee' => array(
'DisplayName' => 'qcs::cam::uin/100000000001:uin/100000000001',
'ID' => 'qcs::cam::uin/100000000001:uin/100000000001',
'Type' => 'CanonicalUser',
),
'Permission' => 'FULL_CONTROL',
),
// ... repeated
),
'Owner' => array(
'DisplayName' => 'qcs::cam::uin/100000000001:uin/100000000001',
'ID' => 'qcs::cam::uin/100000000001:uin/100000000001',
)));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo "$e\\n";
}

参数说明

参数名称
父节点
类型
描述
是否必选
Bucket
String
存储桶名称,格式:BucketName-APPID
Grants
Array
ACL权限列表
Grant
Grants
Array
ACL权限信息
Grantee
Grant
Array
ACL权限信息
Type
Grantee
String
所有者权限类型
Permission
Grant
String
权限类型,可选值: FULL_CONTROL 、 WRITE 、 READ
ACL
String
整体权限类型,可选值:private 、 public-read 、public-read-write
Owner
String
存储桶所有者信息
DisplayName
Grantee/Owner
String
权限所有者的名字信息
ID
Grantee/Owner
String
权限所有者 ID

查询存储桶 ACL

功能说明

获取指定存储桶的访问权限控制列表(ACL)。

方法原型

public Guzzle\\Service\\Resource\\Model getBucketAcl(array $args = array());

请求示例

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部,默认为http
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->getBucketAcl(array(
'Bucket' => 'examplebucket-1250000000' //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo($e);
}

返回结果示例

Array
(
[data:protected] => Array
(
[Owner] => Array
(
[ID] => qcs::cam::uin/100000000001:uin/100000000001
[DisplayName] => qcs::cam::uin/100000000001:uin/100000000001
)

[Grants] => Array
(
[0] => Array
(
[Grantee] => Array
(
[ID] => qcs::cam::uin/100000000001:uin/100000000001
[DisplayName] => qcs::cam::uin/100000000001:uin/100000000001
)

[Permission] => FULL_CONTROL
)

)

[RequestId] => NWE3YzhjMTRfYzdhMzNiMGFfYjdiOF8yYzZmMzU=
)
)

返回结果说明

参数名称
类型
描述
父节点
Grants
Array
ACL 权限列表
Grant
Array
ACL 权限信息
Grants
Grantee
Array
ACL 权限信息
Grant
Permission
String
权限类型,可选值:FULL_CONTROL 、WRITE 、 READ
Grant
Owner
String
存储桶所有者信息
DisplayName
String
权限所有者的名字信息
Grantee/Owner
ID
String
权限所有者 ID
Grantee/Owner

对象 ACL

设置对象 ACL

功能说明

设置指定对象访问权限控制列表(ACL)(PUT Object acl)。

方法原型

public Guzzle\\Service\\Resource\\Model putObjectAcl(array $args = array());

请求示例

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部,默认为http
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->putObjectAcl(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'exampleobject',
'ACL' => 'private',
'Grants' => array(
array(
'Grantee' => array(
'DisplayName' => 'qcs::cam::uin/100000000001:uin/100000000001',
'ID' => 'qcs::cam::uin/100000000001:uin/100000000001',
'Type' => 'CanonicalUser',
),
'Permission' => 'FULL_CONTROL',
),
// ... repeated
),
'Owner' => array(
'DisplayName' => 'qcs::cam::uin/100000000001:uin/100000000001',
'ID' => 'qcs::cam::uin/100000000001:uin/100000000001',
)));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo "$e\\n";
}

参数说明

参数名称
类型
描述
是否必填
Bucket
String
存储桶名称,格式:BucketName-APPID
Key
String
对象键
Grants
Array
ACL权限列表
Grant
Array
ACL权限信息
Grantee
Array
ACL权限信息
Type
String
所有者权限类型
Permission
String
权限类型,可选值:FULL_CONTROL 、WRITE 、READ
ACL
String
整体权限类型,可选值:private 、public-read
Owner
String
存储桶所有者信息
DisplayName
String
权限所有者的名字信息
ID
String
权限所有者 ID

查询对象 ACL

功能说明

查询指定对象的访问权限控制列表(GET Object acl)。

方法原型

public Guzzle\\Service\\Resource\\Model getObjectAcl(array $args = array());

请求示例

<?php

require dirname(__FILE__) . '/../vendor/autoload.php';

$secretId = "SECRETID"; //替换为用户的 secretId,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$secretKey = "SECRETKEY"; //替换为用户的 secretKey,请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi
$region = "ap-beijing"; //替换为用户的 region,已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket
$cosClient = new Qcloud\\Cos\\Client(
array(
'region' => $region,
'scheme' => 'https', //协议头部,默认为http
'credentials'=> array(
'secretId' => $secretId ,
'secretKey' => $secretKey)));

try {
$result = $cosClient->getObjectAcl(array(
'Bucket' => 'examplebucket-1250000000', //存储桶名称,由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket
'Key' => 'exampleobject',
));
// 请求成功
print_r($result);
} catch (\\Exception $e) {
// 请求失败
echo($e);
}

返回结果示例

Array
(
[data:protected] => Array
(
[Owner] => Array
(
[ID] => qcs::cam::uin/100000000001:uin/100000000001
[DisplayName] => qcs::cam::uin/100000000001:uin/100000000001
)

[Grants] => Array
(
[0] => Array
(
[Grantee] => Array
(
[ID] => qcs::cam::uin/100000000001:uin/100000000001
[DisplayName] => qcs::cam::uin/100000000001:uin/100000000001
)

[Permission] => FULL_CONTROL
)

)

[RequestId] => NWE3YzhjMTRfYzdhMzNiMGFfYjdiOF8yYzZmMzU=
)
)

返回结果说明

参数名称
类型
描述
父节点
Grants
Array
ACL权限列表
Grant
Array
ACL权限信息
Grants
Grantee
Array
ACL权限信息
Grant
Permission
String
权限类型,可选值:FULL_CONTROL 、WRITE 、 READ
Grant
Owner
String
存储桶所有者信息
DisplayName
String
权限所有者的名字信息
Grantee / Owner
ID
String
权限所有者 ID
Grantee / Owner