PUT Bucket cors
API Description
You can use this API to set CORS rules for a bucket to allow client browsers to send cross-domain requests.
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 |
|
CorsRules |
indexed array |
Mandatory |
CORS rules of the bucket |
|
ID |
string |
Optional |
CORS rule ID. It is a 1-255 character string. |
|
AllowedMethod |
indexed array of strings |
Mandatory |
HTTP methods allowed by the CORS rule. Possible values are:
|
|
AllowedOrigin |
indexed array of strings |
Mandatory |
Origins (character strings representing domain names) allowed by the CORS rule. Each AllowedOrigin can contain up to one wildcard character (*). |
|
AllowedHeader |
indexed array of strings |
Optional |
Request headers allowed by the CORS rule. Each AllowedHeader can contain up to one wildcard character (*). |
|
MaxAgeSeconds |
integer |
Optional |
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 |
Optional |
Additional response headers allowed by the CORS rule. It cannot contain spaces. |
Returned Result
Field |
Type |
Description |
---|---|---|
HttpStatusCode |
integer |
HTTP status code |
Reason |
string |
Reason description |
RequestId |
string |
Request ID returned by the OBS server |
Sample Code
try{ $resp = $obsClient -> setBucketCors([ 'Bucket' => 'bucketname', 'CorsRules' => [ [ 'ID' => 'rule1', 'AllowedMethod' => ['PUT','POST','GET','DELETE','HEAD'], 'AllowedOrigin' => ['obs.hostname','obs.hostname1'], 'AllowedHeader' => ['obs-header-1'], 'MaxAgeSeconds' => 60 ], [ 'ID' => 'rule2', 'AllowedMethod' => ['PUT','POST','GET'], 'AllowedOrigin' => ['obs.hostname','obs.hostname1'], 'AllowedHeader' => ['header-1','header-2'], 'MaxAgeSeconds' => 50 ] ] ]); printf("RequestId:%s\n", $resp['RequestId']); }catch (Obs\Common\ObsException $obsException){ printf("ExceptionCode:%s\n", $obsException->getExceptionCode()); printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage()); }
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.