• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Node.js SDK)
  4. Bucket-Related APIs
  5. GET Bucket cors

GET Bucket cors

API Description

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

Method Definition

ObsClient.getBucketCors(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

CorsRule

Array

CORS rules of the bucket

  

ID

String

CORS rule ID

AllowedMethod

Array of Strings

HTTP methods allowed by the CORS rule

AllowedOrigin

Array of Strings

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

AllowedHeader

Array of Strings

Request headers allowed by the CORS rule

MaxAgeSeconds

String

Cache duration (in seconds) of the cross-region request result in the client allowed by the CORS rule.

ExposeHeader

Array of Strings

Additional response headers allowed by the CORS rule

Sample Code

obsClient.getBucketCors({
       Bucket : 'bucketname'
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     for(let k=0;k<result.InterfaceResult.CorsRule.length;k++){
                           console.log('CorsRule[',k,']');
                           console.log('CorsRule[ID]-->' + result.InterfaceResult.CorsRule[k]['ID']);
                           console.log('CorsRule[MaxAgeSeconds]-->' + result.InterfaceResult.CorsRule[k]['MaxAgeSeconds']);
                           for (let i=0;i<result.InterfaceResult.CorsRule[k]['AllowedMethod'].length;i++){
                                  console.log('CorsRule[AllowedMethod][' , i ,']-->'+result.InterfaceResult.CorsRule[k]['AllowedMethod'][i]);
                           }
                           for(let i=0;i<in result.InterfaceResult.CorsRule[k]['AllowedOrigin'].length;i++){
                                  console.log('CorsRule[AllowedOrigin][',i ,']-->'+result.InterfaceResult.CorsRule[k]['AllowedOrigin'][i]);
                           }
                           for(let i=0;i<result.InterfaceResult.CorsRule[k]['AllowedHeader'].length;i++){
                                  console.log('CorsRule[AllowedHeader][',i,']-->'+result.InterfaceResult.CorsRule[k]['AllowedHeader'][i]);
                           }
                           for(let i=0;i<result.InterfaceResult.CorsRule[k]['ExposeHeader'].length;i++){
                                  console.log('CorsRule[ExposeHeader][',i ,']-->'+result.InterfaceResult.CorsRule[k]['ExposeHeader'][i]);
                           }      
                     }
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});