All Products
Search
Document Center

ApsaraVideo VOD:Media upload

Last Updated:May 19, 2022

ApsaraVideo VOD servers provide a variety of API operations for media upload. You can upload media files to ApsaraVideo VOD by calling one of these API operations. This topic describes the scenarios in which you can use the server operation SDK for C or C++ to call these operations and provides sample code.

Scenarios

Notice

This topic provides only the sample code of calling API operations, such as the operation for obtaining a URL and a credential for uploading a media file. For more information about the scenarios in which the operations can be used, see the following table.

Operation

Scenario

CreateUploadVideo

  • If you upload media files by using Object Storage Service (OSS) SDKs, you need to use the server operation SDK and call an operation to obtain a URL and a credential for uploading a media file. The obtained URL and credential are Base64-encoded and must be decoded before they are used to initialize an OSS client. For more information, see Upload media files by using OSS SDKs.

  • If you upload media file by using ApsaraVideo VOD clients, you need to use the server operation SDK and call an operation to obtain a URL and a credential for uploading a media file. You can deliver the URL and credential to clients without the need to decode the URL or credential. For more information, see Upload from clients.

RefreshUploadVideo

CreateUploadImage

CreateUploadAttachedMedia

UploadMediaByURL

  • You can call the UploadMediaByURL operation to upload media files by using the URLs of source files. This way, you do not need to download media files to your servers or terminals before you use the server operation SDK to upload the media files to ApsaraVideo VOD.

  • You can call the GetURLUploadInfos operation to query the information about URL-based upload jobs.

GetURLUploadInfos

RegisterMedia

  • After you upload media files to a user-created OSS bucket, you can call the RegisterMedia operation to register the media files and obtain the media IDs of the files. After you register the media files, you can submit transcoding or snapshot jobs for the media files. For more information, see Add a user-created OSS bucket.

Prerequisites

  • The server operation SDK for C or C++ is installed. For more information, see Installation.

  • The server operation SDK for C or C++ is initialized. For more information, see Initialization.

    Note

    In the following examples, an AccessKey pair is used to initialize the server operation SDK.

Sample code

Obtain a URL and a credential for uploading an audio file or a video

You can call the CreateUploadVideo operation to obtain a URL and a credential for uploading an audio file or a video.

For more information about the request and response parameters of this operation, see CreateUploadVideo. The following sample code provides an example:

#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"

/**
 * Obtain a URL and a credential for uploading an audio file or a video.
*/
VodApiResponse createUploadVideo(VodCredential authInfo) {
    string apiName = "CreateUploadVideo";
    map<string, string> args;
    args["Title"] = "sample title";
    args["FileName"] = "filename.mp4";
    return getAcsResponse(authInfo, apiName, args);
}

// The sample code of sending a request.
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = createUploadVideo(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Refresh the credential for uploading an audio file or a video

You can call the RefreshUploadVideo operation to refresh the credential for uploading an audio file or a video.

For more information about the request and response parameters of this operation, see RefreshUploadVideo. The following sample code provides an example:

#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"

/**
 * Refresh the credential for uploading an audio file or a video.
*/
VodApiResponse refreshUploadVideo(VodCredential authInfo) {
    string apiName = "RefreshUploadVideo";
    map<string, string> args;
    args["VideoId"] = "<VideoId>"; // The ID of the video for which you want to refresh the credential.
    return getAcsResponse(authInfo, apiName, args);
}

// The sample code of sending a request.
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = refreshUploadVideo(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Obtain a URL and a credential for uploading an image

You can call the CreateUploadImage operation to obtain a URL and a credential for uploading an image.

For more information about the request and response parameters of this operation, see CreateUploadImage. The following sample code provides an example:

#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"

/**
 * Obtain a URL and a credential for uploading an image.
*/

VodApiResponse createUploadImage(VodCredential authInfo) {
    string apiName = "CreateUploadImage";
    map<string, string> args;
    args["ImageType"] = "cover";
    args["ImageExt"] = "jpg";
    return getAcsResponse(authInfo, apiName, args);
}

// The sample code of sending a request.
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = createUploadImage(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Obtain a URL and a credential for uploading an auxiliary media asset

You can call the CreateUploadAttachedMedia operation to obtain a URL and a credential for uploading an auxiliary media asset.

For more information about the request and response parameters of this operation, see CreateUploadAttachedMedia. The following sample code provides an example:

#include <stdio.h>
#include <string>
#include <map>
#include "vod_sdk/openApiUtil.h"

/**
 * Obtain a URL and a credential for uploading an auxiliary media asset, such as a watermark or subtitle file.
 */

VodApiResponse createUploadAttachedMedia(VodCredential authInfo) {
    string apiName = "CreateUploadAttachedMedia";
    map<string, string> args;
    args["BusinessType"] = "watermark";
    args["MediaExt"] = "gif";
    args["Title"] = "this is a sample title";
    return getAcsResponse(authInfo, apiName, args);
}

// The sample code of sending a request.
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = createUploadAttachedMedia(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Upload multiple media files by using the URLs of source files at a time

You can call the UploadMediaByURL operation to upload multiple media files by using the URLs of source files at a time.

For more information about the request and response parameters of this operation, see UploadMediaByURL. The following sample code provides an example:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * Upload multiple media files by using the URLs of source files at a time.
*/

VodApiResponse uploadMediaByURL(VodCredential authInfo) {
    string apiName = "UploadMediaByURL";
    map<string, string> args;
    args["UploadURLs"] = "http://192.168.0.0/16.mp4";
    Json::Value uploadMetadataList;
    Json::Value uploadMetadata;
    uploadMetadata["SourceUrl"] = "http://192.168.0.0/16.mp4";
    uploadMetadata["Title"] = "upload by url sample";
    uploadMetadataList.append(uploadMetadata);
    args["UploadMetadatas"] = uploadMetadataList.toStyledString();
    return getAcsResponse(authInfo, apiName, args);
}

// The sample code of sending a request.
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = uploadMediaByURL(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Register media assets

You can call the RegisterMedia operation to register media assets.

For more information about the request and response parameters of this operation, see RegisterMedia. The following sample code provides an example:

#include <stdio.h>
#include <string>
#include <map>
#include <jsoncpp/json/json.h>
#include "vod_sdk/openApiUtil.h"

/**
 * Register media assets.
*/

VodApiResponse registerMedia(VodCredential authInfo) {
    string apiName = "RegisterMedia";
    map<string, string> args;
    Json: Value metaDataArray;
    Json: Value metaData;
    metaData["Title"] = "this is a sample";
    metaData["FileURL"] = "https://192.168.0.0/16/vod_sample.mp4";
    metaDataArray.append(metaData);
    args["RegisterMetadatas"] = metaDataArray.toStyledString();
    return getAcsResponse(authInfo, apiName, args);
}

// The sample code of sending a request.
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
    VodApiResponse response = registerMedia(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}