GetSnapshotRequest.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using COSXML.Common;
  6. using COSXML.Model.Object;
  7. using COSXML.CosException;
  8. namespace COSXML.Model.CI
  9. {
  10. /// <summary>
  11. /// 媒体截图
  12. /// <see href="https://cloud.tencent.com/document/product/436/55671"/>
  13. /// </summary>
  14. public sealed class GetSnapshotRequest : ObjectRequest
  15. {
  16. private string localFilePath;
  17. public GetSnapshotRequest(string bucket, string key,
  18. float time, string localFilePath,
  19. int width = 0, int height = 0, string format = "jpg",
  20. string rotate = "auto", string mode = "exactframe"
  21. )
  22. : base(bucket, key)
  23. {
  24. if (time < 0)
  25. {
  26. throw new CosClientException((int)CosClientError.InvalidArgument, "time less than 0");
  27. }
  28. this.method = CosRequestMethod.GET;
  29. this.queryParameters.Add("ci-process", "snapshot");
  30. this.queryParameters.Add("time", time.ToString());
  31. if (width != 0)
  32. {
  33. this.queryParameters.Add("width", width.ToString());
  34. }
  35. if (height != 0)
  36. {
  37. this.queryParameters.Add("height", height.ToString());
  38. }
  39. if (format != "jpg")
  40. {
  41. this.queryParameters.Add("format", format);
  42. }
  43. if (rotate != "auto")
  44. {
  45. this.queryParameters.Add("rotate", rotate);
  46. }
  47. if (mode != "exactframe")
  48. {
  49. this.queryParameters.Add("mode", mode);
  50. }
  51. this.localFilePath = localFilePath;
  52. this.CheckParameters();
  53. }
  54. public override void CheckParameters()
  55. {
  56. if (localFilePath == null)
  57. {
  58. throw new CosClientException((int)CosClientError.InvalidArgument, "localFileName = null");
  59. }
  60. base.CheckParameters();
  61. }
  62. /// <summary>
  63. /// 获取本地文件保存路径
  64. /// </summary>
  65. /// <returns></returns>
  66. public string GetSaveFilePath()
  67. {
  68. return localFilePath;
  69. }
  70. }
  71. }