• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Node.js SDK)
  4. CORS
  5. Viewing CORS Rules

Viewing CORS Rules

You can call ObsClient.getBucketCors to view CORS rules of a bucket. Sample code is as follows:

// Import the OBS library.
var ObsClient = require('./lib/obs');

// Create an instance of ObsClient.
var obsClient = new ObsClient({
    access_key_id: '*** Provide your Access Key ***',       
    secret_access_key: '*** Provide your Secret Key ***',       
    server : 'yourdomainname'
});

obsClient.getBucketCors({
       Bucket:'bucketname'
}, (err, result) => {
       if(err){
              console.log('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
              if(result.CommonMsg.Status < 300 && result.InterfaceResult){
                     for(let k=0;k<result.InterfaceResult.CorsRule.length;k++){
                           console.log('CorsRule[',k,']');
                           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 j=0;j<result.InterfaceResult.CorsRule[k]['AllowedOrigin'].length;j++){
                                  console.log('CorsRule[AllowedOrigin][', j ,']-->'+result.InterfaceResult.CorsRule[k]['AllowedOrigin'][j]);
                            }
                           for(let n=0;n<result.InterfaceResult.CorsRule[k]['AllowedHeader'].length;n++){
                                  console.log('CorsRule[AllowedHeader][', n ,']-->'+result.InterfaceResult.CorsRule[k]['AllowedHeader'][n]);
                           }
                           for(let m=0;m<result.InterfaceResult.CorsRule[k]['ExposeHeader'].length;m++){
                                  console.log('CorsRule[ExposeHeader][', m ,']-->'+result.InterfaceResult.CorsRule[k]['ExposeHeader'][m]);
                           }      
                     }
              }
       }
});