Uploading a Part

API Description

After a multipart upload is initialized, you can use this API to upload a part to a specified bucket by using the multipart upload ID. Except for the part last uploaded whose size ranges from 0 to 5 GB, sizes of the other parts range from 100 KB to 5 GB. The upload part ID ranges from 1 to 10000.

Method Definition

ObsClient.uploadPart(bucketName, objectKey, partNumber, uploadId, object, isFile, partSize, offset, sseHeader, isAttachMd5, md5, progressCallback, autoClose)

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

object

str

or

readable object

Mandatory

Part content to be uploaded

isFile

bool

Optional

Whether object indicates the file path. The default value is False.

offset

int

Optional

Start offset (in bytes) of a part in the source file. The default value is 0.

partSize

int

Optional

Size (in bytes) of a part in the source file. The default value is the file size minus offset.

sseHeader

SseCHeader

Optional

Header for server-side encryption

isAttachMd5

bool

Optional

Whether to automatically calculate the MD5 value of the data to be uploaded. If md5 is configured, this field will be ignored

md5

str

Optional

Base64-encoded MD5 value of the part to be uploaded. It is provided for the OBS server to verify data integrity.

progressCallback

callable

Optional

Callback function for obtaining the upload progress

NOTE:

This callback function contains the following parameters in sequence: number of uploaded bytes, total bytes, and used time (unit: second).

autoClose

bool

Optional

After the upload is complete, data flow is automatically closed. The default value is True.

  • If isAttachMd5 and md5 are used at the same time, isAttachMd5 is ignored.
  • If isFile is True, object indicates the path to the file to be uploaded. If isFile is False and object is a readable object that contains the read attribute, data can be read from the object, otherwise the object content is a character string.

Returned Results

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

UploadPartResponse

Response result of the request for uploading a part

Sample Code

try:
    resp = obsClient.uploadPart('bucketname', 'objectkey', 'partNumber', 'uploadid', 'Hello OBS') 
      
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('etag:', resp.body.etag) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())