All Products
Search
Document Center

ApsaraVideo VOD:Video upload

Last Updated:Oct 09, 2023

This topic describes the video upload feature of the short video SDK for iOS and how to upload a video by using the SDK.

Overview

  • If you use the short video SDK V3.32.0 or earlier, you can call the AliyunVodPublishManager class encapsulated in the upload SDK to upload videos and thumbnails.

  • If you use the short video SDK V3.33.0 or later, you must integrate the upload SDK to upload videos and thumbnails.

Supported editions

Edition

Description

Professional

Yes

Standard

Yes

Basic

No

Note

To upload a video by using the short video SDK Basic Edition, integrate the upload SDK. For more information, see Overview.

Video upload process

Note
  • You must obtain the upload URL and credential before you upload media files. For more information, see Upload URLs and credentials.

  • Before you upload a video edited by using the short video SDK to ApsaraVideo VOD, you must add a thumbnail to the video and export it. For more information, see Export videos.

Upload procedure for the SDK V3.33.0 or later

You must use the upload SDK to upload videos and thumbnails.

  1. Integrate the upload SDK.

    For more information, see Integrate the upload SDK for iOS.

    pod 'VODUpload'
  2. Upload a media file.

    Upload the video and thumbnail by using upload URLs and credentials. For more information, see Upload a file.

Upload procedure for the SDK V3.32.0 or earlier

Call the AliyunVodPublishManager class to upload media files.

Initialize an instance

Initialize an upload instance and configure upload callbacks.

_vodManager = [AliyunVodPublishManager new];
 
// Configure upload callbacks.
_vodManager.uploadCallback = self;

Start the upload.

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

// After you call the CreateUploadVideo operation to obtain the video upload URL and credential or the CreateUploadImage operation to obtain the image upload URL and credential, the following parameters are returned:
//videoPath: the path of the video, which must be the same as the path that you entered when you obtained the upload URL and credential.
//imagePath: the path of the image, which must be the same as the path that you entered when you obtained the upload URL and credential.
//uploadAddress: the upload URL.
//uploadAuth: the upload credential. If the credential expires, see the following section to update the credential.
// Upload the video.
int ret = [_vodManager uploadVideoWithPath:videoPath uploadAddress:uploadAddress uploadAuth:uploadAuth];
// Upload the image.
int ret = [_vodManager uploadImageWithPath:imagePath uploadAddress:uploadAddress uploadAuth:uploadAuth];

Update upload credentials

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 from the onUploadTokenExpired callback. For more information, see RefreshUploadVideo.

// Update the upload credential. uploadAuth indicates the upload credential.
[AliyunVodPublishManager refreshWithUploadAuth:vodUploadAuth];

Configure upload callbacks

// The callback that is invoked when the upload succeeds.
- (void)publishManagerUploadSuccess:(AliyunVodPublishManager *)manager {
}

// The callback that is invoked when the upload fails.
- (void)publishManager:(AliyunVodPublishManager *)manager uploadFailedWithCode:(NSString *)code message:(NSString *)message {
}

// The callback for upload progress. 
- (void)publishManager:(AliyunVodPublishManager *)manager uploadProgressWithUploadedSize:(long long)uploadedSize totalSize:(long long)totalSize  {
}


// The callback that is invoked when the upload token expires. 
- (void)publishManagerUploadTokenExpired:(AliyunVodPublishManager *)manager {
}


// The callback that is invoked when the upload times out and a retry starts.
- (void)publishManagerUploadRetry:(AliyunVodPublishManager *)manager {
}


// The callback that is invoked when the retry is complete and the upload resumes.
- (void)publishManagerUploadRetryResume:(AliyunVodPublishManager *)manager {
}

(Optional) Manage upload

You can pause, resume, or cancel the upload based on your business requirements.

// Pause the upload.
[AliyunVodPublishManager pauseUpload];
// Resume the upload.
[AliyunVodPublishManager resumeUpload];
// Cancel the upload.
[AliyunVodPublishManager cancelUpload];