Updated on 2022-02-10 GMT+08:00

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

func (obsClient ObsClient) DownloadFile(input *DownloadFileInput) (output *GetObjectMetadataOutput, err error)

Request Parameters

Field

Type

Optional or Mandatory

input

*DownloadFileInput

Mandatory

Returned Results

Field

Type

output

*GetObjectMetadataOutput

err

error

Sample Code

func main() {
       input := &obs.DownloadFileInput{}
       input.Bucket = "bucketname"
       input.Key = "objectname"
       input.DownloadFile = "localfile"   // Full path to which objects are downloaded.
       input.EnableCheckpoint = true    // Enable the resumable download mode.
       input.PartSize = 9 * 1024 * 1024  // Set the part size to 9 MB.
       input.TaskNum = 5  // Specify the maximum number of parts that can be concurrently downloaded.
       output, err := obsClient.DownloadFile(input)
       if err == nil {
              fmt.Printf("RequestId:%s\n", output.RequestId)
       } else if obsError, ok := err.(obs.ObsError); ok {
              fmt.Printf("Code:%s\n", obsError.Code)
              fmt.Printf("Message:%s\n", obsError.Message)
       }
}