Help Center> Object Storage Service> SDK Reference> Python> Objects-Related APIs> Downloading Objects - Resumable Transfer

Downloading Objects - Resumable Transfer

API Description

You can use this API to encapsulate and enhance partial download in response to a download failure of large files due to unstable network or program breakdown. This API is used to divide the to-be-downloaded object into multiple parts and download them separately. The download result of each part is recorded in the checkpoint file in real time. The result indicating a successful download is returned only when all parts are successfully downloaded. Otherwise, an exception is thrown to remind the user of calling the API again for re-downloading.

Method Definition

ObsClient.downloadFile(bucketName, objectKey, downloadFile, partSize, taskNum, enableCheckpoint, checkpointFile, header, versionId, progressCallback)

Request Parameters

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name or the name of the file to be downloaded.

downloadFile

str

Mandatory

Full path of the local directory to which the object is downloaded.

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 parts that can be concurrently downloaded. The default value is 1.

enableCheckpoint

bool

Optional

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

checkpointFile

str

Optional

File used to record the download progress. This parameter is effective only in the resumable download mode. If the value is empty, the file is in the same local directory as the downloaded object.

header

GetObjectHeader

Optional

Additional header of the request for downloading objects

versionId

str

Optional

Object version ID

progressCallback

callable

Optional

Callback function for obtaining the download progress

NOTE:

This function contains the following parameters in sequence: number of downloaded bytes, total number of bytes, and used time (unit: second). For details about the sample code, see Downloading an Object – Obtaining the Download Progress.

Returned Results

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

GetObjectMetadataResponse

Response result of the request for obtaining object metadata

Sample Code

downloadFile = 'localfile'
taskNum = 5
partSize = 10 * 1024 * 1024
enableCheckpoint = True
try:
    resp = obsClient.downloadFile('bucketname', 'objectkey', downloadFile, 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())