媒体上传

本文档提供了C/C++ SDK媒体上传相关功能的API调用示例,包含获取上传地址和凭证、注册媒资信息等。要实现完整的媒体文件上传,可配合客户端上传,也可以直接使用服务端C/C++SDK进行媒体上传。

初始化客户端

使用前请先初始化客户端,请参见初始化

获取视频上传地址和凭证

调用CreateUploadVideo接口,完成获取视频上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadVideo。调用示例如下:

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

/**
 * 获取视频上传地址和凭证
*/
VodApiResponse createUploadVideo(VodCredential authInfo) {
    string apiName = "CreateUploadVideo";
    map<string, string> args;
    args["Title"] = "sample title";
    args["FileName"] = "filename.mp4";
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
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());
}

刷新视频上传凭证

调用RefreshUploadVideo接口,完成刷新视频上传凭证功能。

接口参数和返回字段请参见RefreshUploadVideo。调用示例如下:

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

/**
 * 刷新视频上传凭证
*/
VodApiResponse refreshUploadVideo(VodCredential authInfo) {
    string apiName = "RefreshUploadVideo";
    map<string, string> args;
    args["VideoId"] = "<VideoId>"; // 替换成需要的视频ID
    return getAcsResponse(authInfo, apiName, args);
}

// 请求示例
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());
}

获取图片上传地址和凭证

调用CreateUploadImage接口,完成获取图片上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadImage。调用示例如下:

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

/**
 * 获取图片上传地址和凭证
*/

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

// 请求示例
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());
}

获取辅助媒资上传地址和凭证

调用CreateUploadAttachedMedia接口,完成获取辅助媒资上传地址和凭证功能。

接口参数和返回字段请参见CreateUploadAttachedMedia。调用示例如下:

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

/**
 * 获取辅助媒资(水印、字幕等)上传地址和凭证
 */

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);
}

// 请求示例
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());
}

URL批量拉取上传

调用UploadMediaByURL接口,完成URL批量拉取上传功能。

接口参数和返回字段请参见UploadMediaByURL。调用示例如下:

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

/**
 * URL批量拉取上传
*/

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);
}

// 请求示例
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());
}

注册媒资信息

调用RegisterMedia接口,完成注册媒资信息功能。

接口参数和返回字段请参见RegisterMedia。调用示例如下:

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

/**
 * 注册媒资信息
*/

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);
}

// 请求示例
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());
}