Updated on 2023-03-16 GMT+08:00

GET Bucket cors

API Description

You can use this API to obtain the CORS rules of a specified bucket.

Method Definition

1. ObsClient->setBucketCors(array $parameter)
2. ObsClient->setBucketCorsAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

CorsRules

indexed array

CORS rules of the bucket

  

ID

string

CORS rule ID

AllowedMethod

indexed array of strings

HTTP methods allowed by the CORS rule

AllowedOrigin

indexed array of strings

Origins (character strings representing domain names) allowed by the CORS rule

AllowedHeader

indexed array of strings

Request headers allowed by the CORS rule

MaxAgeSecond

integer

Cache duration (in seconds) of the cross-region request result in the client allowed by the CORS rule. The value must be an integer.

ExposeHeader

indexed array of strings

Additional response headers allowed by the CORS rule

Sample Code

try{
       $resp = $obsClient -> getBucketCors([
              'Bucket' => 'bucketname'
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       foreach ($resp['CorsRules'] as $index => $corsRule){
              printf("CorsRule[%d]\n", $index + 1);
              printf("MaxAgeSeconds:%s\n", print_r($corsRule['MaxAgeSeconds'], true));
              printf("AllowedMethod:%s\n", print_r($corsRule['AllowedMethod'], true));
              printf("AllowedOrigin:%s\n", print_r($corsRule['AllowedOrigin'], true));
              printf("AllowedHeader:%s\n", print_r($corsRule['AllowedHeader'], true));
              printf("ExposeHeader:%s\n", print_r($corsRule['ExposeHeader'],true));
       }
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());              
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}