tencent cloud

Smart Media Hosting

Download

PDF
Modo Foco
Tamanho da Fonte
Última atualização: 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()


Ajuda e Suporte

Esta página foi útil?

comentários