putBucketAcl.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require dirname(__FILE__) . '/../vendor/autoload.php';
  3. $secretId = "COS_SECRETID"; //"云 API 密钥 SecretId";
  4. $secretKey = "COS_SECRETKEY"; //"云 API 密钥 SecretKey";
  5. $region = "ap-beijing"; //设置一个默认的存储桶地域
  6. $cosClient = new Qcloud\Cos\Client(
  7. array(
  8. 'region' => $region,
  9. 'schema' => 'https', //协议头部,默认为http
  10. 'credentials'=> array(
  11. 'secretId' => $secretId ,
  12. 'secretKey' => $secretKey)));
  13. try {
  14. $result = $cosClient->putBucketAcl(array(
  15. //bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
  16. 'Bucket' => 'examplebucket-125000000',
  17. 'ACL' => 'private',
  18. 'Grants' => array(
  19. array(
  20. 'Grantee' => array(
  21. 'DisplayName' => 'qcs::cam::uin/100000000001:uin/100000000001',
  22. 'ID' => 'qcs::cam::uin/100000000001:uin/100000000001',
  23. 'Type' => 'CanonicalUser',
  24. ),
  25. 'Permission' => 'FULL_CONTROL',
  26. ),
  27. // ... repeated
  28. ),
  29. 'Owner' => array(
  30. 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098',
  31. 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098',
  32. )));
  33. // 请求成功
  34. print_r($result);
  35. } catch (\Exception $e) {
  36. // 请求失败
  37. echo "$e\n";
  38. }