PUT Bucket cors
API Description
You can use this API to set CORS rules for a bucket to allow the client browsers to send cross-domain requests.
Method Definition
ObsClient.setBucketCors
Request Parameter
|
Field |
Type |
Optional or Mandatory |
Description |
|
|---|---|---|---|---|
|
Bucket |
String |
Mandatory |
Bucket name |
|
|
CorsRules |
Array |
Mandatory |
CORS rules of the bucket |
|
|
ID |
String |
Optional |
CORS rule ID. The value is a string of no more than 255 characters. |
|
|
AllowedMethod |
Array of Strings |
Mandatory |
HTTP methods allowed by the CORS rule. Possible values are:
|
|
|
AllowedOrigin |
Array of Strings |
Mandatory |
Origins (character strings representing domain names) allowed by the CORS rule. The value can contain one wildcard character (*). Each AllowedOrigin can only contain one or zero wildcard character (*). |
|
|
AllowedHeader |
Array of Strings |
Optional |
Request headers allowed by the CORS rule. The value must not contain spaces. The value can contain one wildcard character (*). Each AllowedHeader can only contain one or zero wildcard character (*). |
|
|
MaxAgeSeconds |
Number |
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 |
Array of Strings |
Optional |
Additional response headers allowed by the CORS rule. The value must not contain spaces. |
|
Returned Result (InterfaceResult)
|
Field |
Type |
Description |
|---|---|---|
|
RequestId |
String |
Request ID returned by the OBS server |
Sample Code
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
}
]
},(err, result) => {
if(err){
console.error('Error-->' + err);
}else{
if(result.CommonMsg.Status < 300){
console.log('RequestId-->' + result.InterfaceResult.RequestId);
}else{
console.log('Code-->' + result.CommonMsg.Code);
console.log('Message-->' + result.CommonMsg.Message);
}
}
});
Last Article: GET Bucket versioning
Next Article: GET Bucket cors
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.