• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (PHP 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

1. ObsClient->optionsObject(array $parameter)
2. ObsClient->optionsObjectAsync(array $parameter, callable $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

indexed array of strings

Mandatory

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

  • GET
  • PUT
  • HEAD
  • POST
  • DELETE

AccessControlRequestHeaders

indexed array of strings

Optional

HTTP headers in a cross-domain request

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason 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

try{
       $resp = $obsClient -> optionsBucket([
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'Origin' => 'http://www.a.com',       
              'AccessControlRequestMethods' => ['POST']
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       printf("AllowOrigin:%s\n", $resp['AllowOrigin']);
       printf("AllowHeader:%s\n", $resp['AllowHeader']);
       printf("AllowMethod:%s\n", $resp['AllowMethod']);
       printf("ExposeHeader:%s\n", $resp['ExposeHeader']);
       printf("MaxAgeSeconds:%s\n", $resp['MaxAgeSeconds']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}