All Products
Search
Document Center

Apsara Video SDK:Upload videos

Last Updated:Mar 28, 2024

This topic describes the upload feature provided by Short video SDK for Android. This topic also describes how to use Short video SDK for Android to upload videos.

Overview

You can upload media files such as audio, video, and image files to ApsaraVideo VOD (VOD) for storage. For more information, see Overview. An upload SDK provides a set of methods to implement the upload feature. You can use the AliyunIVodCompose core class to produce and upload edited videos on a dedicated user interface (UI). This facilitates video production and merging on a client. Alibaba Cloud Short video SDK allows you to call the AliyunIVodCompose core class to upload videos.

SDK editions and whether the video upload feature is supported

Edition

Supported

Professional Edition

Yes

Standard Edition

Yes

Basic Edition

No

Related classes

Class

Description

AliyunIVodCompose

A core class of the upload feature. You can use the core class to initialize an upload instance, upload video or image files, as well as update upload credentials.

AliyunComposeFactory

A factory class.

Procedure

  1. If you want to use a client, such as an application or a web client, to upload a video or image by using an upload SDK, the client first sends a request to the application server to obtain the upload URL and credential.

  2. The application server sends a request to ApsaraVideo VOD to obtain the URL and credential for uploading the video or image.

  3. If the request is successful, ApsaraVideo VOD returns the upload URL and credential to the application server. ApsaraVideo VOD also returns a video ID for video upload, and an image URL for image upload.

  4. The application server returns the upload URL and credential to the client.

  5. You upload files from the local device to Object Storage Service (OSS) buckets by using the upload address and credentials.

  6. OSS returns the upload results.

Initialize an upload instance

Initialize an upload instance.

// Create an instance.
AliyunComposeFactory.createAliyunVodCompose();

// Initialize the instance.
AliyunIVodCompose.init(Context context);

Obtain upload URLs and credentials

The AliyunIVodCompose class uploads media files by using upload URLs and credentials. Therefore, you must obtain upload URLs and credentials for media files that you want to upload. For more information, see CreateUploadVideo.

Note

The upload does not start after you obtain the upload URLs and credentials. You must call relevant methods to start the upload.

Upload a file

Upload a media file such as a video or an image.

// Upload a video or an image based on the upload URL and credential.
// videoPath: the path of the video file. Make sure that the path of the video file is the same as the path that you specify to obtain the upload URL and credential. 
// imagePath: the path of the image file. Make sure that the path of the image file is the same as the path that you specify to obtain the upload URL and credential.
// uploadAddress: the upload URL.
// uploadAuth: the upload credential. If the credential expires, update the upload credential.
// aliyunVodUploadCallBack: the upload callback.
// Upload the video.
AliyunIVodCompose.uploadVideoWithVod(String videoPath, String uploadAddress, String uploadAuth, AliyunIVodUploadCallBack aliyunVodUploadCallBack);

// Upload the image.
AliyunIVodCompose.uploadImageWithVod(String imagePath, String uploadAddress, String uploadAuth, AliyunIVodUploadCallBack aliyunVodUploadCallBack);

Update the upload credential.

The Expiration variable of the UploadAuth parameter specifies the validity period of the upload credential. By default, a upload credential has a validity period of 3,000 seconds. After the upload credential expires, you need to obtain a new upload credential in the onUploadTokenExpired callback that is returned when the credential expires. For more information, see RefreshUploadVideo.

// Update the upload credential. The uploadAuth parameter indicates the upload credential.
AliyunIVodCompose.refreshWithUploadAuth(String uploadAuth);

Release resources

After the video is uploaded, destroy the instance and release the resources.

AliyunIVodCompose.release();

Control upload

You can pause, continue, and cancel the upload during the upload process.

// Pause the upload.
AliyunIVodCompose.pauseUpload();
// Resume the upload.
AliyunIVodCompose.resumeUpload();
// Cancel the upload.
AliyunIVodCompose.cancelUpload();