• Object Storage Service

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

OPTIONS Object

API Description

You can use this API to pre-request an object in a specified bucket that is configured with CORS.

Method Definition

ObsClient.optionsObject(parameter, callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Key

String

Mandatory

Object name

Origin

String

Mandatory

Origin of the cross-domain request specified by the pre-request. Generally, it is a domain name.

AccessControlRequestMethods

Array of Strings

Mandatory

HTTP methods in the cross-domain request. Possible values are:

  • GET
  • PUT
  • HEAD
  • POST
  • DELETE

AccessControlRequestHeaders

Array of Strings

Optional

HTTP headers in the cross-domain request

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

AllowOrigin

String

If Origin in the request meets the CORS rules of the bucket, AllowedOrigin in the CORS rules is returned.

AllowHeader

String

If AccessControlRequestHeaders in the request meets the CORS rules of the bucket, AllowedHeader in the CORS rules is returned.

AllowMethod

String

AllowedMethod in the CORS rules of the bucket

ExposeHeader

String

ExposeHeader in the CORS rules of the bucket

MaxAgeSeconds

String

MaxAgeSeconds in the CORS rules of the bucket

Sample Code

obsClient.optionsObject({
       Bucket:'bucketname',
       Key : 'objectkey',
       Origin : 'http://www.a.com',
       AccessControlRequestMethods : ['POST']
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('AllowOrigin-->' + result.InterfaceResult.AllowOrigin);  
                     console.log('AllowHeader-->' + result.InterfaceResult.AllowHeader);  
                     console.log('AllowMethod-->' + result.InterfaceResult.AllowMethod);  
                     console.log('ExposeHeader-->' + result.InterfaceResult.ExposeHeader);      
                     console.log('MaxAgeSeconds-->' + result.InterfaceResult.MaxAgeSeconds);           
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});