• Object Storage Service

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

PUT Object - Copy

API Description

You can use this API to create a copy for an object in a specified bucket.

Method Definition

1. ObsClient->copyObject(array $parameter)
2. ObsClient->copyObjectAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Target bucket name

Key

string

Mandatory

Target object name

ACL

string

Optional

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

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

StorageClass

string

Optional

Storage class of the object. Possible values are:

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

CopySource

string

Mandatory

Parameter used to specify the source bucket, source object, and source object version ID which can be null. It is in the format of SourceBucketName/SourceObjectName?versionId=SourceObjectVersionId.

CopySourceIfMatch

string

Optional

Copies the source object if its ETag is the same as the one specified by this parameter; otherwise, an exception is thrown.

CopySourceIfModifiedSince

string

or

\DateTime

Optional

Copies the source object if it is changed after the time specified by this parameter; otherwise, an exception is thrown. If this parameter value is a character string, it must conform to the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt.

CopySourceIfNoneMatch

string

Optional

Copies the source object if its ETag is different from the one specified by this parameter; otherwise, an exception is thrown.

CopySourceIfUnmodifiedSince

string

or

\DateTime

Optional

Copies the source object if it is changed before the time specified by this parameter; otherwise, an exception is thrown. If this parameter value is a character string, it must conform to the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt.

CacheControl

string

Optional

Rewrites the Cache-Control header in the response.

ContentDisposition

string

Optional

Rewrites the Content-Disposition header in the response.

ContentEncoding

string

Optional

Rewrites the Content-Encoding header in the response.

ContentLanguage

string

Optional

Rewrites the Content-Language header in the response.

ContentType

string

Optional

Rewrites the Content-Type header in the response.

Expires

string

Optional

Rewrites the Expires header in the response.

MetadataDirective

string

Optional

Whether to copy source object attributes to the target object. Possible values are:

  • ObsClient::CopyMetadata (Default value; Attributes of the target object are copied from the source object.)
  • ObsClient::ReplaceMetadata (Attributes of the target object are replaced with values specified in the request parameter.)

Metadata

associative array

Optional

Customized metadata of the target object

WebsiteRedirectLocation

string

Optional

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

SseKms

string

Optional

Algorithm used to encrypt the target object in SSE-KMS mode. The value can be:

  • aws:kms

SseKmsKey

string

Optional

Master key used to encrypt the target object in SSE-KMS mode. The value can be null.

SseC

string

Optional

Algorithm used to encrypt the target object in SSE-C mode. The value can be:

  • AES256

SseCKey

string

Optional

Key used to encrypt the target object in SSE-C mode, which is calculated by using AES-256

CopySourceSseC

string

Optional

Algorithm used to decrypt the source object in SSE-C mode. The value can be:

  • AES256

CopySourceSseCKey

string

Optional

Key used to decrypt the source object in SSE-C mode, which is calculated by using AES-256

NOTE:
  • If the object copy request includes CopySourceIfUnmodifiedSince, CopySourceIfMatch, CopySourceIfModifiedSince, or CopySourceIfNoneMatch, and the specified condition is not met, an exception will be thrown with HTTP status code 412 Precondition Failed returned.
  • CopySourceIfModifiedSince and CopySourceIfNoneMatch can be used together. So do CopySourceIfUnmodifiedSince and CopySourceIfMatch.

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

ETag

string

ETag of the target object

LastModified

string

Time when the last modification was made to the object

VersionId

string

Version ID of the target object. This field is null if versioning is not enabled for the target bucket.

CopySourceVersionId

string

Version ID of the source object. This field is null if versioning is not enabled for the source bucket.

SseKms

string

Algorithm used in SSE-KMS encryption

SseKmsKey

string

Master 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 -> copyObject([
              'Bucket' => 'bucketname',
              'Key' => 'objectkey',
              'CopySource' => 'srcbucketname/srcobjectkey',
              'Metadata' => ['meta1' => 'value1']
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
       printf("ETag:%s\n", $resp['ETag']);
       printf("VersionId:%s\n", $resp['VersionId']);
       printf("CopySourceVersionId:%s\n", $resp['CopySourceVersionId']);
       printf("LastModified:%s\n", $resp['LastModified']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}