getObjectUrl.php 901 B

12345678910111213141516171819202122232425262728
  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. $local_path = "/data/exampleobject";
  14. try {
  15. $bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID
  16. $key = "exampleobject"; //对象在存储桶中的位置,即对象键
  17. $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes'); //签名的有效时间
  18. // 请求成功
  19. echo $signedUrl;
  20. } catch (\Exception $e) {
  21. // 请求失败
  22. print_r($e);
  23. }