All Products
Search
Document Center

Media upload

Last Updated: Jul 11, 2019

This topic describes how to use the C/C++ server SDK to call server operations, for example, to obtain the upload URL and credential and register media asset information. To upload complete media files, you can use the client upload SDK together with the upload URL and credential or directly use the C/C++ server upload SDK.

Initialize a client

Initialize a client before using the SDK. For more information, see initVodClient.

Obtain the video upload URL and credential

For more information about the request and response parameters, see CreateUploadVideo.

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

/**
 * Method for obtaining the video upload URL and credential
*/
VodApiResponse createUploadVideo(VodCredential authInfo) {
    string apiName = "CreateUploadVideo";
    map<string, string> args;
    args["Title"] = "sample title";
    args["FileName"] = "filename.mp4";
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = createUploadVideo(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Refresh the video upload credential

For more information about the request and response parameters, see RefreshUploadVideo.

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

/**
 * Method for refreshing the video upload credential
*/
VodApiResponse refreshUploadVideo(VodCredential authInfo) {
    string apiName = "RefreshUploadVideo";
    map<string, string> args;
    args["VideoId"] = "<VideoId>"; // Sets the video ID.
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = refreshUploadVideo(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Obtain the image upload URL and credential

For more information about the request and response parameters, see CreateUploadImage.

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

/**
 * Method for obtaining the image upload URL and credential
*/

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

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = createUploadImage(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Obtain the upload URL and credential for an attached media asset

For more information about the request and response parameters, see CreateUploadAttachedMedia.

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

/**
 * Method for obtaining the upload URL and credential for an attached 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);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = createUploadAttachedMedia(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Upload multiple videos based on mezzanine file URLs

For more information about the request and response parameters, see UploadMediaByURL.

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

/**
 * Method for uploading multiple videos based on mezzanine file URLs
*/

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

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = uploadMediaByURL(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}

Register media asset information

For more information about the request and response parameters, see RegisterMedia.

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

/**
 * Method for registering media asset information
*/

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://xxxxxx.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4";
    metaDataArray.append(metaData);
    args["RegisterMetadatas"] = metaDataArray.toStyledString();
    return getAcsResponse(authInfo, apiName, args);
}

// Call example
void main() {
    VodCredential authInfo = initVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
    VodApiResponse response = registerMedia(authInfo);
    printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
}