• Object Storage Service

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

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

Request Parameter

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 headers in PUT Object - Copy

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

CopyObjectResponse

Response result of PUT Object - Copy

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())