tencent cloud

Smart Media Hosting

Product Introduction
Product Overview
Feature Description
Product Strengths
Use Cases
Basic Concept
Purchase Guide
Quick Start
Create Media Library
Initiate request
Service Level API Document
History
Introduction
API Category
Making API Requests
PaaS Service APIs
Official Cloud Disk APIs
Data Types
Error Codes
Business Level API Document
Introduction
Access Token Operation API
Tenant Space Operation API
File Operation API
Directory or Album Operation API
Recycle Bin Operation API
Quota Operation API
Query Task Operation API
Search Operation API
Historical Version Operations API
Directory and File Batch Operation API
Collection Operation API
Error Codes
SDK Documentation
Android SDK
iOS SDK
HarmonyOS SDK
FAQs
Enterprise Network Disk
Product Introduction
Purchase Guide
Quick Start
FAQs
Service Level Agreement
Glossary

Download

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 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()


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan