• Object Storage Service

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

PUT Object

API Description

You can use this API to upload an object to a specified bucket.

Method Definition

1. ObsClient->putObject(array $parameter)
2. ObsClient->putObjectAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

Key

string

Mandatory

Object name

ACL

string

Optional

Pre-defined access policy specified for the to-be-created object. Possible values are:

  • ObsClient::AclPrivate
  • ObsClient::AclPublicRead
  • ObsClient::AclPublicReadWrite
  • ObsClient::AclAuthenticatedRead
  • ObsClient::AclBucketOwnerRead
  • ObsClient::AclBucketOwnerFullControl

StorageClass

string

Optional

Storage class specified for the to-be-created object. Possible values are:

  • ObsClient::StorageClassStandard
  • ObsClient::StorageClassWarm
  • ObsClient::StorageClassCold

Body

string

or

resource

or

GuzzleHttp\Psr7\Stream

Optional

Object content to be uploaded

SourceFile

string

Optional

Path to the source file of the object

Metadata

associative array

Optional

Customized metadata of the object

WebsiteRedirectLocation

string

Optional

Location where the object is redirected to, when the bucket is configured with website hosting.

ContentType

string

Optional

MIME type of the object

ContentLength

integer

Optional

Object size in bytes

ContentMD5

string

Optional

Base64-encoded MD5 value of the object data to be uploaded. It is provided for the OBS server to verify data integrity.

SseKms

string

Optional

Algorithm used in SSE-KMS encryption. The value can be:

  • aws:kms

SseKmsKey

string

Optional

Master key used in SSE-KMS encryption. The value can be null.

SseC

string

Optional

Algorithm used in SSE-C encryption. The value can be:

  • AES256

SseCKey

string

Optional

Key used in SSE-C encryption. It is calculated by using AES-256.

NOTE:
  • Body and SourceFile cannot be used together.
  • If both Body and SourceFile are null, the size of the object to be uploaded is 0 bytes.

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

ObjectURL

string

Object URL

ETag

string

Object ETag

VersionId

string

Object version ID

StorageClass

string

Storage class of the object. When the storage class is STANDARD, the value is null.

SseKms

string

Algorithm used in SSE-KMS encryption

SseKmsKey

string

Key used in SSE-KMS encryption

SseC

string

Algorithm used in SSE-C encryption

SseCKeyMd5

string

MD5 value of the key used in SSE-C encryption

Sample Code

try{
       $resp = $obsClient -> putObject([
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'Metadata' => ['meta1' => 'value1', 'meta2' => 'value2'],
//            'SourceFile' => 'localfile',
              'Body' => 'Hello OBS',
              'ContentType' => 'text/plain'
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       printf("VersionId:%s\n", $resp['VersionId']);
       printf("StorageClass:%s\n", $resp['StorageClass']);
       printf("ETag:%s\n", $resp['ETag']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}