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

Uploading

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2026-01-07 11:03:07

Introduction

This document provides an API overview and SDK example code for file upload.

Advanced Upload

Feature Overview

The upload method automatically performs fast upload, simple upload, and multi-part upload logic internally. The generated uploadTask can be used externally to suspend, restore, or cancel.

Example Code

The SDK supports Uri and input stream. Following is an example with Uri:
//Local files to upload
val file = File.createTempFile("uploadBigMedia", ".jpg")
//Get upload task
val uploadTask = smh.upload(
//Name to upload to the server
name = "uploadBigMedia.jpg",
//Folder location, root directory is selected by default
dir = Directory(),
//Local file Uri
uri = Uri.fromFile(file),
status listener
stateListener = object : SMHStateListener {
override fun onStateChange(request: SMHRequest, state: SMHTransferState) {
Log.i("Test", "onStateChange $state")
}
},
progress listener
progressListener = object: SMHProgressListener {
override fun onProgressChange(request: SMHRequest, progress: Long, target: Long) {
Log.i("Test", "Progress change $progress/$target")
}
},
result listener
resultListener = object: SMHResultListener {
override fun onSuccess(request: SMHRequest, result: SMHResult) {
Log.i("Test", "onSuccess")
}
override fun onFailure(
request: SMHRequest,
smhException: SMHException?,
smhClientException: SMHClientException?
) {
Log.i("Test", "onFailure $smhException and ")
}
}
)
launch {
delay(5000)
//Suspend upload task
uploadTask.pause(true)
}
//Start upload task
uploadTask.start()
delay(2000)
//Resume upload task
uploadTask.resume()


Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan