This topic describes the upload feature provided by the short video SDK for Android and how to use the SDK to upload media files.

Overview

ApsaraVideo VOD allows you to upload media files such as audio, video, and image files to Object Storage Service (OSS) buckets allocated to ApsaraVideo VOD. For more information, see Overview. The upload SDK provides a set of operations to implement the upload feature. You can use the AliyunIVodCompose core class to produce and upload edited videos on a dedicated user interface (UI). The Alibaba Cloud short video SDK allows you to call the core class AliyunIVodCompose to upload videos.

Supported editions

Edition Supported
Professional Yes
Standard Yes
Basic No

Related classes

Class Description
AliyunIVodCompose The 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 The factory class.

Video upload process

  1. If a user wants to use a client, such as an application or a web client, to upload a video or image by using the upload SDK, the client sends a request to the user application server to obtain the upload address and credentials.
  2. The application server initiates requests to ApsaraVideo VOD by calling the CreateUploadVideo or CreateUploadImage operation.
  3. If requests are successful, ApsaraVideo VOD returns the upload address, upload credentials, VideoId, and ImageURL to the application server.
  4. The application server returns the upload address and upload credentials to the client.
  5. The user uploads files from the local computer to OSS buckets by using the upload address and credentials.
  6. OSS returns the upload results.

Initialize an instance

Initialize an upload instance. For more information about the parameters that are used in the code, see Related classes.
// Create an instance.
AliyunComposeFactory.createAliyunVodCompose();

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

Obtain the video based on the upload address and credentials

You can use the AliyunIVodCompose class to upload a video or an image based on the upload address and credentials. Before you upload the video and image, obtain the upload address and credentials. For more information, see CreateUploadVideo or CreateUploadImage.
Note You can only obtain the upload address and credentials from this step.

Upload media files

You can upload media files such as videos and images. For more information about the parameters that are used in the code, see Related classes.
// Upload a video or an image based on the upload address and credentials.
// videoPath: the address of the video file. Make sure that the address of the video file that you entered is the same as the address that you obtained. 
// imagePath: the address of the image file. Make sure that the address of the image file that you entered is the same as the address that you obtained.
// uploadAddress: the upload address.
// uploadAuth: the upload credentials. If the credentials expire, 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 upload credentials

The upload credentials are time-sensitive. The Expiration variable in the UploadAuth field specifies the validity period of the upload credentials. The default validity period is 3,000 seconds. If the upload credentials expire, you must call onUploadTokenExpired to obtain new upload credentials. For more information, see RefreshUploadVideo.
// Update upload credentials. uploadAuth: the upload credentials.
AliyunIVodCompose.refreshWithUploadAuth(String uploadAuth);

Release resources

After the upload is complete, destroy the upload instance that you used and release the resources. For more information about the parameters that are used in the code, see Related classes.
AliyunIVodCompose.release();

Manage the upload process

You can pause, continue, and cancel the upload during the upload process. For more information about the parameters that are required in the code, see Related classes.
// Pause the upload.
AliyunIVodCompose.pauseUpload();
// Continue the upload.
AliyunIVodCompose.resumeUpload();
// Cancel the upload.
AliyunIVodCompose.cancelUpload();