全部产品
云市场

媒体上传

更新时间:2018-12-29 11:43:47

初始化客户端

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

获取视频上传地址和凭证

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.CreateUploadVideo
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. CreateUploadVideoRequest request = new CreateUploadVideoRequest();
  15. request.Title = "this is a sample title";
  16. request.FileName = "sample.mp4";
  17. // request.Tags = "tags1,tags2";
  18. // request.Description = "this is a sample description";
  19. // request.CoverURL = "http://cover.sample.com/sample.jpg";
  20. // request.CateId = -1;
  21. // request.TemplateGroupId = "278840921dee4963bb5862b43aeb2273";
  22. // 初始化客户端
  23. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  24. // 发起请求,并得到响应结果
  25. CreateUploadVideoResponse response = client.GetAcsResponse(request);
  26. Console.WriteLine("RequestId = " + response.RequestId);
  27. Console.WriteLine("UploadAddress = " + response.UploadAddress);
  28. Console.WriteLine("UploadAuth = " + response.UploadAuth);
  29. }
  30. catch (ServerException ex)
  31. {
  32. Console.WriteLine(ex.ToString());
  33. }
  34. catch (ClientException ex)
  35. {
  36. Console.WriteLine(ex.ToString());
  37. }
  38. }
  39. }
  40. }

刷新视频上传凭证

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.Sample
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. RefreshUploadVideoRequest request = new RefreshUploadVideoRequest();
  15. request.VideoId = "视频ID";
  16. // 初始化客户端
  17. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  18. // 发起请求,并得到 response
  19. RefreshUploadVideoResponse response = client.GetAcsResponse(request);
  20. Console.WriteLine("RequestId = " + response.RequestId);
  21. Console.WriteLine("UploadAddress = " + response.UploadAddress);
  22. Console.WriteLine("UploadAuth = " + response.UploadAuth);
  23. }
  24. catch (ServerException ex)
  25. {
  26. Console.WriteLine(ex.ToString());
  27. }
  28. catch (ClientException ex)
  29. {
  30. Console.WriteLine(ex.ToString());
  31. }
  32. }
  33. }
  34. }

获取图片上传地址和凭证

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.Sample
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. CreateUploadImageRequest request = new CreateUploadImageRequest();
  15. request.ImageType = "cover";
  16. request.ImageExt = "jpg";
  17. // 初始化客户端
  18. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  19. // 发起请求,并得到 response
  20. CreateUploadImageResponse response = client.GetAcsResponse(request);
  21. Console.WriteLine("RequestId = " + response.RequestId);
  22. Console.WriteLine("UploadAddress = " + response.UploadAddress);
  23. Console.WriteLine("UploadAuth = " + response.UploadAuth);
  24. }
  25. catch (ServerException ex)
  26. {
  27. Console.WriteLine(ex.ToString());
  28. }
  29. catch (ClientException ex)
  30. {
  31. Console.WriteLine(ex.ToString());
  32. }
  33. }
  34. }
  35. }

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

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace CreateUploadAttachedMedia
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. // 构造请求
  14. CreateUploadAttachedMediaRequest request = new CreateUploadAttachedMediaRequest();
  15. request.BusinessType = "watermark";
  16. request.MediaExt = "gif";
  17. request.Title = "this is a sample";
  18. // 初始化客户端
  19. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  20. // 发起请求,并得到 response
  21. CreateUploadAttachedMediaResponse response = client.GetAcsResponse(request);
  22. Console.WriteLine("RequestId = " + response.RequestId);
  23. Console.WriteLine("MediaId = " + response.MediaId);
  24. Console.WriteLine("MediaURL = " + response.MediaURL);
  25. Console.WriteLine("UploadAddress = " + response.UploadAddress);
  26. Console.WriteLine("UploadAuth = " + response.UploadAuth);
  27. }
  28. catch (ServerException ex)
  29. {
  30. Console.WriteLine(ex.ToString());
  31. }
  32. catch (ClientException ex)
  33. {
  34. Console.WriteLine(ex.ToString());
  35. }
  36. }
  37. }
  38. }

URL批量拉取上传

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.UploadMediaByURL
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. UploadMediaByURLRequest request = new UploadMediaByURLRequest();
  14. request.UploadMetadatas = "[{\"SourceUrl\":\"http://vod.aliyun.com/test.mp4\",\"Title\":\"upload by url sample\"}]";
  15. // 初始化客户端
  16. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  17. // 发起请求,并得到 response
  18. UploadMediaByURLResponse response = client.GetAcsResponse(request);
  19. Console.WriteLine("RequestId = " + response.RequestId);
  20. }
  21. catch (ServerException ex)
  22. {
  23. Console.WriteLine(ex.ToString());
  24. }
  25. catch (ClientException ex)
  26. {
  27. Console.WriteLine(ex.ToString());
  28. }
  29. }
  30. }
  31. }

注册媒资信息

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

  1. using System;
  2. using Aliyun.Acs.Core;
  3. using Aliyun.Acs.Core.Exceptions;
  4. using Aliyun.Acs.vod.Model.V20170321;
  5. namespace Aliyun.Acs.vod.Sdk.RegisterMedia
  6. {
  7. class MainClass
  8. {
  9. public static void Main(string[] args)
  10. {
  11. try
  12. {
  13. RegisterMediaRequest request = new RegisterMediaRequest();
  14. request.RegisterMetadatas = "[{\"Title\":\"register media test\",\"FileURL\":\"https://test.oss-cn-shanghai.aliyuncs.com/vod-test/aaa.mp4\"}]";
  15. // 初始化客户端
  16. DefaultAcsClient client = InitVodClient("<Your AccessKeyId>", "<Your AccessKeySecret>");
  17. // 发起请求,并得到 response
  18. RegisterMediaResponse response = client.GetAcsResponse(request);
  19. Console.WriteLine("RequestId = " + response.RequestId);
  20. if (response.RegisteredMediaList != null && response.RegisteredMediaList.Count > 0) {
  21. foreach(var media in response.RegisteredMediaList) {
  22. Console.WriteLine("MediaId = " + media.MediaId);
  23. Console.WriteLine("FileURL = " + media.FileURL);
  24. Console.WriteLine("NewRegister = " + media.NewRegister);
  25. }
  26. }
  27. if (response.FailedFileURLs != null && response.FailedFileURLs.Count > 0) {
  28. foreach (var fileURL in response.FailedFileURLs) {
  29. Console.WriteLine("FailedFileURL = " + fileURL);
  30. }
  31. }
  32. }
  33. catch (ServerException ex)
  34. {
  35. Console.WriteLine(ex.ToString());
  36. }
  37. catch (ClientException ex)
  38. {
  39. Console.WriteLine(ex.ToString());
  40. }
  41. }
  42. }
  43. }