Updated on 2023-03-16 GMT+08:00

PUT Object - Copy

API Description

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

Method Definition

ObsClient.copyObject

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 control policy specified during object copy

StorageClass

String

Optional

Storage class of the object. Possible values are:

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 error code is returned.

CopySourceIfModifiedSince

String

Optional

Copies the source object if it is changed after the time specified by this parameter; otherwise, an error code is returned. This parameter must conform with 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 error code is returned.

CopySourceIfUnmodifiedSince

String

Optional

Copies the source object if it is changed before the time specified by this parameter; otherwise, an error code is returned. This parameter must conform with the HTTP time format specified in http://www.ietf.org/rfc/rfc2616.txt.

CacheControl

String

Optional

When an object is copied, this parameter rewrites the Cache-Control header in the response.

ContentDisposition

String

Optional

When an object is copied, this parameter rewrites the Content-Disposition header in the response.

ContentEncoding

String

Optional

When an object is copied, this parameter rewrites the Content-Encoding header in the response.

ContentLanguage

String

Optional

When an object is copied, this parameter rewrites the Content-Language header in the response.

ContentType

String

Optional

When an object is copied, this parameter rewrites the Content-Type header in the response.

Expires

String

Optional

When an object is copied, this parameter rewrites the Expires header in the response.

MetadataDirective

String

Optional

Replication policy

Metadata

Object

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

SuccessActionRedirect

String

Optional

Redirection address after the copy is successful

SseKms

String

Optional

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

  • kms

SseKmsKey

String

Optional

Master key used to encrypt a target object in SSE-KMS encryption, which can be left null

SseC

String

Optional

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

  • AES256

SseCKey

Buffer

Optional

Key used to encrypt a target object in SSE-C mode, which is calculated by using the AES256 algorithm.

CopySourceSseC

String

Optional

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

  • AES256

CopySourceSseCKey

Buffer

Optional

Key used to decrypt a source object in SSE-C mode, which is calculated by using the AES256 algorithm.

  • If CopySourceIfUnmodifiedSince, CopySourceIfMatch, CopySourceIfModifiedSince, or CopySourceIfNoneMatch is included and its specified condition is not met, 412 Precondition Failed will be returned.
  • CopySourceIfModifiedSince and CopySourceIfNoneMatch can be used together. So do CopySourceIfUnmodifiedSince and CopySourceIfMatch.

Returned Result (InterfaceResult)

Field

Type

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 target 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

obsClient.copyObject({
       Bucket:'bucketname',
       Key:'objectkey',
       CopySource:'srcbucketname/srcobjectkey',
       Metadata:{meta1:'value1'}
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('ETag-->' + result.InterfaceResult.ETag);
                     console.log('VersionId-->' + result.InterfaceResult.VersionId);
                     console.log('CopySourceVersionId-->' + result.InterfaceResult.CopySourceVersionId);
                     console.log('LastModified-->' + result.InterfaceResult.LastModified);             
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});