全部产品
云市场

媒体上传

更新时间:2018-12-28 21:12:35

本文档为Node.js版获取上传地址和凭证、注册媒资信息等服务端API的调用示例,要实现完整的媒体文件上传,可配合 客户端上传 实现上传功能。

初始化客户端

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

获取视频上传地址和凭证

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

  1. // 请求示例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. client.request("CreateUploadVideo", {
  4. Title: 'this is a sample',
  5. FileName: 'filename.mp4'
  6. }, {}).then(function (response) {
  7. console.log('VideoId = ' + response.VideoId);
  8. console.log('UploadAddress = ' + response.UploadAddress);
  9. console.log('UploadAuth = ' + response.UploadAuth);
  10. console.log('RequestId = ' + response.RequestId);
  11. }).catch(function (response) {
  12. console.log('ErrorCode = ' + response.data.Code);
  13. console.log('ErrorMessage = ' + response.data.Message);
  14. console.log('RequestId = ' + response.data.RequestId);
  15. });

刷新视频上传凭证

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

  1. // 请求示例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. client.request("RefreshUploadVideo", {
  4. VideoId: 'VideoId'
  5. }, {}).then(function (response) {
  6. console.log('UploadAddress = ' + response.UploadAddress);
  7. console.log('UploadAuth = ' + response.UploadAuth);
  8. console.log('RequestId = ' + response.RequestId);
  9. }).catch(function (response) {
  10. console.log('ErrorCode = ' + response.data.Code);
  11. console.log('ErrorMessage = ' + response.data.Message);
  12. console.log('RequestId = ' + response.data.RequestId);
  13. });

获取图片上传地址和凭证

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

  1. // 请求示例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. client.request("CreateUploadImage", {
  4. ImageType: 'cover',
  5. ImageExt: 'jpg'
  6. }, {}).then(function (response) {
  7. console.log('ImageId = ' + response.ImageId);
  8. console.log('ImageURL = ' + response.ImageURL);
  9. console.log('UploadAddress = ' + response.UploadAddress);
  10. console.log('UploadAuth = ' + response.UploadAuth);
  11. console.log('RequestId = ' + response.RequestId);
  12. }).catch(function (response) {
  13. console.log('ErrorCode = ' + response.data.Code);
  14. console.log('ErrorMessage = ' + response.data.Message);
  15. console.log('RequestId = ' + response.data.RequestId);
  16. });

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

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

  1. // 请求示例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. client.request("CreateUploadAttachedMedia", {
  4. BusinessType: 'watermark',
  5. MediaExt: 'gif',
  6. Title: 'this is a sample'
  7. }, {}).then(function (response) {
  8. console.log('MediaId = ' + response.MediaId);
  9. console.log('MediaURL = ' + response.MediaURL);
  10. console.log('UploadAddress = ' + response.UploadAddress);
  11. console.log('UploadAuth = ' + response.UploadAuth);
  12. console.log('RequestId = ' + response.RequestId);
  13. }).catch(function (response) {
  14. console.log('ErrorCode = ' + response.data.Code);
  15. console.log('ErrorMessage = ' + response.data.Message);
  16. console.log('RequestId = ' + response.data.RequestId);
  17. });

URL批量拉取上传

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

  1. // 请求示例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. var url = 'http://xxxx.mp4';
  4. var uploadMetadatas = [{
  5. SourceUrl: url,
  6. Title: 'upload by url sample'
  7. }];
  8. client.request("UploadMediaByURL", {
  9. UploadURLs: url,
  10. UploadMetadatas: JSON.stringify(uploadMetadatas)
  11. }, {}).then(function (response) {
  12. console.log('UploadJobs = ');
  13. console.log(response.UploadJobs);
  14. console.log('RequestId = ' + response.RequestId);
  15. }).catch(function (response) {
  16. console.log('ErrorCode = ' + response.data.Code);
  17. console.log('ErrorMessage = ' + response.data.Message);
  18. console.log('RequestId = ' + response.data.RequestId);
  19. });

注册媒资信息

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

  1. // 请求示例
  2. var client = initVodClient('<Your AccessKeyId>','<Your AccessKeySecret>');
  3. var url = 'http://xxxx.mp4';
  4. var registerMetadatas = [{
  5. FileURL: url,
  6. Title: 'this is a sample'
  7. }];
  8. client.request("RegisterMedia", {
  9. RegisterMetadatas: JSON.stringify(registerMetadatas)
  10. }, {}).then(function (response) {
  11. if (response.FailedFileURLs && response.FailedFileURLs.length > 0){
  12. for (var i=0; i<response.FailedFileURLs.length; i++) {
  13. console.log('FailedFileURL = ' + response.FailedFileURLs[i]);
  14. }
  15. }
  16. if (response.RegisteredMediaList && response.RegisteredMediaList.length > 0){
  17. for (var i=0; i<response.RegisteredMediaList.length; i++) {
  18. console.log('MediaId = ' + response.RegisteredMediaList[i].MediaId);
  19. console.log('FileURL = ' + response.RegisteredMediaList[i].FileURL);
  20. console.log('NewRegister = ' + response.RegisteredMediaList[i].NewRegister);
  21. }
  22. }
  23. console.log('RequestId = ' + response.RequestId);
  24. }).catch(function (response) {
  25. console.log('ErrorCode = ' + response.data.Code);
  26. console.log('ErrorMessage = ' + response.data.Message);
  27. console.log('RequestId = ' + response.data.RequestId);
  28. });