tencent cloud

Smart Media Hosting

Download

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-01-07 11:03:07

Introduction

This document provides an API overview for file download as well as SDK example code.

Advanced Download

Feature Overview

The download method automatically performs logic for downloading to local or streaming as well as resuming upload. The generated downloadTask allows external operations such as suspend, restore, and cancel.

Example Code

//download to local file
val file = File.createTempFile("dowloadBigMedia", ".jpg")
//get download task
val downloadTask = smh.download(
//file name to download
name = "uploadBigMedia.jpg",
//Folder location, root directory is selected by default
dir = Directory(),
//download to local file path
localFullPath = file.absolutePath,
//status listener
stateListener = object : SMHStateListener {
override fun onStateChange(request: SMHRequest, state: SMHTransferState) {
Log.i("testDownloadTask", "onStateChange $state")
}
},
//progress listener
progressListener = object: SMHProgressListener {
override fun onProgressChange(request: SMHRequest, progress: Long, target: Long) {
Log.i("testDownloadTask", "Progress change $progress/$target")
}
},
//result listener
resultListener = object: SMHResultListener {
override fun onSuccess(request: SMHRequest, result: SMHResult) {
Log.i("testDownloadTask", "onSuccess")
//download result
if(result is DownloadFileResult){
Log.i("testDownloadTask", "bytesTotal: ${result.bytesTotal}")
Log.i("testDownloadTask", "content: ${result.content.toString()}")
Log.i("testDownloadTask", "crc64: ${result.crc64}")
Log.i("testDownloadTask", "key: ${result.key}")
Log.i("testDownloadTask", "meta: ${result.meta?.entries?.joinToString()}")
}
}
override fun onFailure(
request: SMHRequest,
smhException: SMHException?,
smhClientException: SMHClientException?
) {
Log.i("testDownloadTask", "onFailure $smhException, $smhClientException")
}
}
)
launch {
delay(5000)
//suspend download task
downloadTask.pause()
}
//start the download task
downloadTask.start()
delay(2000)
//resume download task
downloadTask.resume()


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백