tencent cloud

All product documents
Video on Demand
Upload SDK for Flutter
Last updated: 2025-03-07 16:08:37
Upload SDK for Flutter
Last updated: 2025-03-07 16:08:37
VOD provides an SDK for uploading videos from Flutter clients. For details about the upload process, see Guide.
SDK Name
Cloud Video on Demand Flutter Upload SDK
Version Number
V1.5.0
SDK Introduction
Provides a scenario for app end-users to upload local videos to the Cloud Video on Demand platform.
Download SDK
1. Click to download the Flutter Upload SDK and source code, unzip the downloaded compressed package, and you can see the vod_upload directory.
2. The upload source code is located in the vod_upload/lib directory.

Environment Setup

Flutter:
Flutter 3.0.0 and above
Dart 2.19.2 and below 4.0
Android:
Android Studio 3.5 and above
Android 4.1 and above
iOS:
Xcode 11.0 and above
iOS 9.0 and above
Make sure your project has a valid developer signature set up

Quick Integration

Add Dependencies

1. Copy the SDK source code to your project directory.
2. Add the SDK to pubspec.yaml
vod_upload_flutter:
path: ./vod_upload
3. Run the command flutter pub get in the root directory of your project to refresh the dependencies.
Note:
1. It is recommended to run flutter pub get command separately in the root directory, SDK directory, and SDK Example directory to avoid potential errors.
2. The SDK Example directory is the test project for the SDK. You can delete it if not needed.

Add Native Configurations

Android

Add the following configurations to AndroidManifest.xml.
<!-- Network permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

iOS

Add the following configuration to Info.plist in iOS.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Note:
If you want to run the provided Demo in the SDK, you should also declare permission to use the photo library.

Usage

1. Import the file.
import 'package:vod_upload_flutter/txugc_publish.dart';
2. Create an object.
var uploader = TXUGCPublish(
id: "",
);
Note:
The id can be any string as long as it is unique. The main purpose is to map the Flutter object to the native layer object.

API

Upload Video

uploader.publishVideo(TXPublishParam(
signature: "",
videoPath: "",
fileName: "",
));

Cancel Video Upload

uploader.cancelUploadVideo();

Resume Video Upload

uploader.resumeUploadVideo(TXPublishParam(
signature: "",
videoPath: "",
fileName: "",
));

Upload Media File

uploader.publishMedia(TXMediaPublishParam(
signature: "",
mediaPath: "",
fileName: "",
));

Cancel Media File Upload

uploader.cancelUploadMedia();

Resume Media File Upload

uploader.resumeUploadMedia(TXMediaPublishParam(
signature: "",
mediaPath: "",
fileName: "",
));

Prepare Upload

TXUGCPublish.prepareUpload(signature, callback);
Note:
Prepare upload is a static method.

Get Upload Information

// On Android, you can only get information during the upload process, while on iOS, you can get information throughout the process.
uploader.getStatusInfo();

Report AppId

uploader.setAppId(appId);

Set Video Upload Callback

uploader.setVideoListener(listener);

Set Media Upload Callback

uploader.setMediaListener(listener);

Callback Interfaces and Parameter Explanations

Video Upload Parameters

TXPublishParam
Field
Type
Required
Explanation
Default Value
signature
string
Yes
Signature
null
videoPath
string
Yes
Video path
null
fileName
string
Yes
File name
null
enableResume
boolean
No
Enable resumable upload
true
enableHttps
boolean
No
Enable HTTPS
false
coverPath
string
No
Cover image
null
enablePreparePublish
boolean
No
Enable prepare upload (can be manually triggered if disabled)
true
sliceSize
integer
No
Chunk size (minimum 1M, maximum 10M, default 0, which means the file size divided by 10)
0
concurrentCount
integer
No
Concurrent number of chunk uploads (if <=0, the default value of 2 will be used)
-1

Media Upload Parameters

TXMediaPublishParam
Field
Type
Required
Explanation
Default Value
signature
string
Yes
Signature
null
mediaPath
string
Yes
Media file path
null
fileName
string
Yes
File name
null
enableResume
boolean
No
Enable resumable upload
true
enableHttps
boolean
No
Enable HTTPS
false
coverPath
string
No
Cover image
null
enablePreparePublish
boolean
No
Enable prepare upload (can be manually triggered if disabled)
true
sliceSize
integer
No
Chunk size (minimum 1M, maximum 10M, default 0, which means the file size divided by 10)
0
concurrentCount
integer
No
Concurrent number of chunk uploads (if <=0, the default value of 2 will be used)
-1

Video Upload Callback

ITXVideoPublishListener
Method
Return Type
Explanation
onPublishProgress
void
Upload progress callback
onPublishComplete
void
Upload completion callback
Parameter explanation:
onPublishProgress
Parameter
Type
Explanation
uploadBytes
integer
Number of bytes uploaded
totalBytes
integer
Total number of bytes
onPublishComplete
Parameter
Type
Explanation
result
TXPublishResult
Upload result
TXPublishResult
Parameter
Type
Explanation
retCode
integer
Error code
descMsg
string
Error description
videoId
string
Video file ID
videoURL
string
Video playback URL
coverURL
string
Cover image storage URL

Media File Upload Callback

ITXMediaPublishListener
Method
Return Type
Explanation
onMediaPublishProgress
void
Upload progress callback
onMediaPublishComplete
void
Upload completion callback
Parameter explanation:
onMediaPublishProgress
Parameter
Type
Explanation
uploadBytes
integer
Number of bytes uploaded
totalBytes
integer
Total number of bytes
onMediaPublishComplete
Parameter
Type
Explanation
result
TXMediaPublishResult
Upload result
TXMediaPublishResult
Parameter
Type
Explanation
retCode
integer
Error code
descMsg
string
Error description
mediaId
string
Media file ID
mediaURL
string
Media file URL

Prepare Upload Callback

IPrepareUploadCallback
Method
Return Type
Explanation
onLoading
void
Prepare upload start callback
onFinish
void
Prepare upload completion callback

Upload Status Information

ReportInfo
Field
Type
Explanation
reqType
string
Request type, indicating the current step
errCode
string
Error code
cosErrCode
string
COS upload error code
errMsg
string
Error message
reqTime
string
Request start time for the current step
reqTimeCost
string
Time spent on the current step
fileSize
string
File size
fileType
string
File type
fileName
string
File name
fileId
string
File ID
appId
string
VOD App ID set through TXUGCPublish
reqServerIp
string
IP address accessed during the current step
reportId
string
Custom report ID provided by the customer, can be passed through the TXUGCPublish constructor
reqKey
string
Request key, usually composed of the last modification time of the file and the start time of this upload
vodSessionKey
string
Session key from the VOD server, obtained from the upload request interface
cosRegion
string
Region accessed during the current upload
requestId
string
Request ID for the current COS upload
cosVideoPath
string
Path for the current COS video upload
vodErrCode
integer
Signaling request error code
useHttpDNS
integer
Whether to use httpDns for domain name resolution
useCosAcc
integer
Whether COS domain name acceleration is enabled
tcpConnTimeCost
integer
Time spent on connecting to the server in the current step
recvRespTimeCost
integer
Time spent on receiving server response in the current step

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon