Copying an Object

API Description

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

Method Definition

ObsClient.copyObject(sourceBucketName, sourceObjectKey, destBucketName, destObjectKey, metadata, headers, versionId)

Request Parameters

Field

Type

Optional or Mandatory

Description

sourceBucketName

str

Mandatory

Source bucket name

sourceObjectKey

str

Mandatory

Source object name

versionId

str

Optional

Source object version ID

destBucketName

str

Mandatory

Target bucket name

destObjectKey

str

Mandatory

Target object name

metadata

dict

Optional

Customized metadata of the target object

headers

CopyObjectHeader

Optional

Additional header of the request for copying an object

Returned Results

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

CopyObjectResponse

Response result of the request for copying an object

Sample Code

try:
    resp = obsClient.copyObject('sourcebucketname', 'sourceobjectkey', 'destbucketname', 'destobjectkey', metadata={'meta1' : 'value1'}) 
          
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('etag:', resp.body.etag) 
        print('lastModified:', resp.body.lastModified) 
        print('versionId:', resp.body.versionId) 
        print('copySourceVersionId:', resp.body.copySourceVersionId) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())