Copying a Part

API Description

After a multipart upload is initialized, you can use this API to copy a part of a multipart upload task to a specified bucket.

Method Definition

ObsClient.copyPart(bucketName, objectKey, partNumber, uploadId, copySource, copySourceRange, destSseHeader, sourceSseHeader)

Request Parameters

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

partNumber

int

Mandatory

Part number, which ranges from 1 to 10000

uploadId

str

Mandatory

Multipart upload ID

copySource

str

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.

copySourceRange

str

Optional

Copy range of the source object. The value range is [0, source object length-1] and is in the format of bytes=x-y. If the maximum length of copySourceRange is larger than the length of the source object minus 1, the length of the source object minus 1 is used.

destSseHeader

SseCHeader

or

SseKmsHeader

Optional

Header for server-side encryption. It is used to encrypt the target object.

sourceSseHeader

SseCHeader

Optional

Header for server-side decryption. It is used to decrypt the source object.

Returned Results

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

CopyPartResponse

Response result of the request for copying a part

Sample Code

try:
    resp = obsClient.copyPart('bucketname', 'objectkey', 'partNumber', 'uploadid', 'sourcebucketname/sourceobjectkey', '0-15') 
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('etagValue:', resp.body.etagValue) 
        print('modifiedDate:', resp.body.modifiedDate) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())