• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Other APIs
  5. Resumable Upload

Resumable Upload

API Description

This API is an encapsulated and enhanced version of multipart upload, and aims to eliminate large file upload failures caused by poor network conditions and program breakdowns.

Method Definition

ObsClient.uploadFile(bucketName, objectKey, uploadFile, partSize, taskNum, enableCheckpoint, checkpointFile, checkSum, metadata)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

uploadFile

str

Mandatory

Local file to be uploaded

partSize

int

Optional

Part size, in bytes. The value ranges from 100 KB to 5 GB and defaults to 5 MB.

taskNum

int

Optional

Maximum number of threads that can be concurrently executed for upload. The default value is 1.

enableCheckpoint

bool

Optional

Whether to enable the resumable upload mode. The default value is False, which indicates that this mode is disabled.

checkpointFile

str

Optional

File used to record the upload progress. This parameter is effective only in the resumable upload mode. If the value is None, the file is in the same directory as the local file to be uploaded.

checkSum

bool

Optional

Whether to verify the content of the to-be-uploaded file. This parameter is valid only in the resumable upload mode. The default value is False, which indicates that the content of the file will not be verified.

metadata

dict

Optional

Customized metadata of the object

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

CompleteMultipartUploadResponse

Response result of Complete Multipart Upload

Sample Code

uploadFile = 'localfile'
taskNum = 5
partSize = 10 * 1024 * 1024
enableCheckpoint = True
try:
    resp = obsClient.uploadFile('bucketname', 'objectkey', uploadFile, partSize, taskNum, enableCheckpoint)
    if resp.status < 300:    
        print('requestId:', resp.requestId)    
    else:    
        print('errorCode:', resp.errorCode)    
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())