tencent cloud

Smart Media Hosting

Uploading

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 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()


도움말 및 지원

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

피드백