• Object Storage Service

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

Resumable Download

API Description

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

Method Definition

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

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

downloadFile

str

Optional

Full path of the local directory to which the object is downloaded. If the value is None, the downloaded object is saved in the directory where the program is executed.

partSize

int

Optional

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

enableCheckpoint

bool

Optional

Whether to enable the resumable download mode. The default value is False, which indicates 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 None, the file is in the same local directory as the downloaded object.

header

GetObjectHeader

Optional

Additional header in GET Object

versionId

str

Optional

Object version ID

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

GetObjectMetadataResponse

Response result of Obtain 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())