更新时间:2022-02-10 GMT+08:00
断点续传下载
功能说明
对范围下载的封装和加强,解决下载大对象到本地时由于网络不稳定或程序崩溃导致下载失败的问题。
方法定义
func (obsClient ObsClient) DownloadFile(input *DownloadFileInput) (output *GetObjectMetadataOutput, err error)
请求参数
参数名 |
类型 |
约束 |
---|---|---|
input |
必选 |
返回结果
参数名 |
类型 |
---|---|
output |
|
err |
error |
代码样例
func main() { input := &obs.DownloadFileInput{} input.Bucket = "bucketname" input.Key = "objectname" input.DownloadFile = "localfile" // localfile为下载对象的本地文件全路径 input.EnableCheckpoint = true // 开启断点续传模式 input.PartSize = 9 * 1024 * 1024 // 指定分段大小为9MB input.TaskNum = 5 // 指定分段下载时的最大并发数 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) } }
父主题: 其他接口