媒体上传
点播服务端提供丰富的上传接口,支持开发者采用不同的上传方式实现媒体上传。本文介绍C/C++ SDK调用服务端上传接口的使用场景和调用示例。
使用场景
注意
本文仅提供API调用示例,即在点播服务中获取上传凭证和地址等操作示例。要实现完整的媒体文件上传逻辑,请参考下表跳转至对应的上传方式和使用场景。
接口 | 使用场景 |
---|---|
| |
前提条件
接口调用示例
获取音/视频上传地址和凭证
调用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());
}