更新时间:2023-11-08 GMT+08:00
分享

查看托管配置

开发过程中,您有任何问题可以在github上提交issue,或者在华为云对象存储服务论坛中发帖求助。接口参考文档详细介绍了每个接口的参数和使用方法。

您可以通过ObsClient->getBucketWebsite查看桶的托管配置。以下代码展示了如何查看托管配置:

// 引入依赖库
require 'vendor/autoload.php';
// 使用源码安装时引入SDK代码库
// require 'obs-autoloader.php';
// 声明命名空间
use Obs\ObsClient;
// 创建ObsClient实例
$obsClient = new ObsClient ( [ 
      //推荐通过环境变量获取AKSK,这里也可以使用其他外部引入方式传入,如果使用硬编码可能会存在泄露风险。
      //您可以登录访问管理控制台获取访问密钥AK/SK,获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html
      'key' => getenv('ACCESS_KEY_ID'),
      'secret' => getenv('SECRET_ACCESS_KEY'),
      'endpoint' => 'https://your-endpoint'
] );

$resp = $obsClient->getBucketWebsite ( [ 
       'Bucket' => 'bucketname' 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
printf ( "IndexDocument[Suffix]:%s\n", $resp ['IndexDocument'] ['Suffix'] );
printf ( "ErrorDocument[Key]:%s\n", $resp ['ErrorDocument'] ['Key'] );
foreach ( $resp ['RoutingRules'] as $index => $routingRule ) {
       printf ( "RoutingRules[%d]\n", $index + 1 );
       printf ( "Condition[HttpErrorCodeReturnedEquals]:%s\n", $routingRule ['Condition'] ['HttpErrorCodeReturnedEquals'] );
       printf ( "Condition[KeyPrefixEquals]:%s\n", $routingRule ['Condition'] ['KeyPrefixEquals'] );
       printf ( "Redirect[HostName]:%s\n", $routingRule ['Redirect'] ['HostName'] );
       printf ( "Redirect[Protocol]:%s\n", $routingRule ['Redirect'] ['Protocol'] );
       printf ( "Redirect[HttpRedirectCode]:%s\n", $routingRule ['Redirect'] ['HttpRedirectCode'] );
       printf ( "Redirect[ReplaceKeyPrefixWith]:%s\n", $routingRule ['Redirect'] ['ReplaceKeyPrefixWith'] );
       printf ( "Redirect[ReplaceKeyWith]:%s\n", $routingRule ['Redirect'] ['ReplaceKeyWith'] );
}

相关文档