全部产品
云市场

媒体上传

更新时间:2019-01-15 17:25:14

本文档为C/C++版获取上传地址和凭证、注册媒资信息等服务端API的调用示例,要实现完整的媒体文件上传,可配合 客户端上传,也可以直接使用 服务端C/C++上传SDK

初始化客户端

使用前请先初始化客户端,参考 initVodClient 接口。

获取视频上传地址和凭证

接口参数和返回字段请参考 CreateUploadVideo

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include "vod_sdk/openApiUtil.h"
  5. /**
  6. * 获取视频上传地址和凭证
  7. */
  8. VodApiResponse createUploadVideo(VodCredential authInfo) {
  9. string apiName = "CreateUploadVideo";
  10. map<string, string> args;
  11. args["Title"] = "sample title";
  12. args["FileName"] = "filename.mp4";
  13. return getAcsResponse(authInfo, apiName, args);
  14. }
  15. // 请求示例
  16. void main() {
  17. VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. VodApiResponse response = createUploadVideo(authInfo);
  19. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  20. }

刷新视频上传凭证

接口参数和返回字段请参考 RefreshUploadVideo

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include "vod_sdk/openApiUtil.h"
  5. /**
  6. * 刷新视频上传凭证
  7. */
  8. VodApiResponse refreshUploadVideo(VodCredential authInfo) {
  9. string apiName = "RefreshUploadVideo";
  10. map<string, string> args;
  11. args["VideoId"] = "<VideoId>"; // 替换成需要的视频ID
  12. return getAcsResponse(authInfo, apiName, args);
  13. }
  14. // 请求示例
  15. void main() {
  16. VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  17. VodApiResponse response = refreshUploadVideo(authInfo);
  18. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  19. }

获取图片上传地址和凭证

接口参数和返回字段请参考 CreateUploadImage

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include "vod_sdk/openApiUtil.h"
  5. /**
  6. * 获取图片上传地址和凭证
  7. */
  8. VodApiResponse createUploadImage(VodCredential authInfo) {
  9. string apiName = "CreateUploadImage";
  10. map<string, string> args;
  11. args["ImageType"] = "cover";
  12. args["ImageExt"] = "jpg";
  13. return getAcsResponse(authInfo, apiName, args);
  14. }
  15. // 请求示例
  16. void main() {
  17. VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. VodApiResponse response = createUploadImage(authInfo);
  19. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  20. }

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

接口参数和返回字段请参考 CreateUploadAttachedMedia

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include "vod_sdk/openApiUtil.h"
  5. /**
  6. * 获取辅助媒资(水印、字幕等)上传地址和凭证
  7. */
  8. VodApiResponse createUploadAttachedMedia(VodCredential authInfo) {
  9. string apiName = "CreateUploadAttachedMedia";
  10. map<string, string> args;
  11. args["BusinessType"] = "watermark";
  12. args["MediaExt"] = "gif";
  13. args["Title"] = "this is a sample title";
  14. return getAcsResponse(authInfo, apiName, args);
  15. }
  16. // 请求示例
  17. void main() {
  18. VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. VodApiResponse response = createUploadAttachedMedia(authInfo);
  20. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  21. }

URL批量拉取上传

接口参数和返回字段请参考 UploadMediaByURL

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include <jsoncpp/json/json.h>
  5. #include "vod_sdk/openApiUtil.h"
  6. /**
  7. * URL批量拉取上传
  8. */
  9. VodApiResponse uploadMediaByURL(VodCredential authInfo) {
  10. string apiName = "UploadMediaByURL";
  11. map<string, string> args;
  12. args["UploadURLs"] = "http://xxxx.mp4";
  13. Json::Value uploadMetadataList;
  14. Json::Value uploadMetadata;
  15. uploadMetadata["SourceUrl"] = "http://xxxx.mp4";
  16. uploadMetadata["Title"] = "upload by url sample";
  17. uploadMetadataList.append(uploadMetadata);
  18. args["UploadMetadatas"] = uploadMetadataList.toStyledString();
  19. return getAcsResponse(authInfo, apiName, args);
  20. }
  21. // 请求示例
  22. void main() {
  23. VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  24. VodApiResponse response = uploadMediaByURL(authInfo);
  25. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  26. }

注册媒资信息

接口参数和返回字段请参考 RegisterMedia

  1. #include <stdio.h>
  2. #include <string>
  3. #include <map>
  4. #include <jsoncpp/json/json.h>
  5. #include "vod_sdk/openApiUtil.h"
  6. /**
  7. * 注册媒资信息
  8. */
  9. VodApiResponse registerMedia(VodCredential authInfo) {
  10. string apiName = "RegisterMedia";
  11. map<string, string> args;
  12. Json::Value metaDataArray
  13. Json::Value metaData
  14. metaData["Title"] = "this is a sample";
  15. metaData["FileURL"] = "https://xxxxxx.oss-cn-shanghai.aliyuncs.com/vod_sample.mp4";
  16. metaDataArray.append(metaData);
  17. args["RegisterMetadatas"] = metaDataArray.toStyledString();
  18. return getAcsResponse(authInfo, apiName, args);
  19. }
  20. // 请求示例
  21. void main() {
  22. VodCredential authInfo = initVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  23. VodApiResponse response = registerMedia(authInfo);
  24. printf("httpCode: %d, result: %s\n", response.httpCode, response.result.c_str());
  25. }