UploadPartCopyRequest.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using COSXML.Common;
  5. using COSXML.Model.Tag;
  6. using COSXML.CosException;
  7. namespace COSXML.Model.Object
  8. {
  9. /// <summary>
  10. /// 分片复制
  11. /// <see href="https://cloud.tencent.com/document/product/436/12633"/>
  12. /// </summary>
  13. public sealed class UploadPartCopyRequest : ObjectRequest
  14. {
  15. /// <summary>
  16. /// 拷贝的数据源
  17. /// <see href="Model.Tag.CopySourceStruct"/>
  18. /// </summary>
  19. private CopySourceStruct copySourceStruct;
  20. private int partNumber = -1;
  21. private String uploadId = null;
  22. public UploadPartCopyRequest(string bucket, string key, int partNumber, string uploadId)
  23. : base(bucket, key)
  24. {
  25. this.method = CosRequestMethod.PUT;
  26. this.partNumber = partNumber;
  27. this.uploadId = uploadId;
  28. }
  29. /// <summary>
  30. /// 设置拷贝数据源
  31. /// <see href="Model.Tag.CopySourceStruct"/>
  32. /// </summary>
  33. /// <param name="copySource"></param>
  34. public void SetCopySource(CopySourceStruct copySource)
  35. {
  36. this.copySourceStruct = copySource;
  37. }
  38. /// <summary>
  39. /// 设置拷贝的分片范围
  40. /// </summary>
  41. /// <param name="start"></param>
  42. /// <param name="end"></param>
  43. public void SetCopyRange(long start, long end)
  44. {
  45. if (start >= 0 && end >= start)
  46. {
  47. string bytes = String.Format("bytes={0}-{1}", start, end);
  48. SetRequestHeader(CosRequestHeaderKey.X_COS_COPY_SOURCE_RANGE, bytes);
  49. }
  50. }
  51. public override void CheckParameters()
  52. {
  53. if (copySourceStruct == null)
  54. {
  55. throw new CosClientException((int)CosClientError.InvalidArgument, "copy source = null");
  56. }
  57. else
  58. {
  59. copySourceStruct.CheckParameters();
  60. }
  61. if (requestUrlWithSign != null)
  62. {
  63. return;
  64. }
  65. base.CheckParameters();
  66. if (partNumber <= 0)
  67. {
  68. throw new CosClientException((int)CosClientError.InvalidArgument, "partNumber < 1");
  69. }
  70. if (uploadId == null)
  71. {
  72. throw new CosClientException((int)CosClientError.InvalidArgument, "uploadID = null");
  73. }
  74. }
  75. protected override void InternalUpdateQueryParameters()
  76. {
  77. try
  78. {
  79. this.queryParameters.Add("partNumber", partNumber.ToString());
  80. }
  81. catch (ArgumentException)
  82. {
  83. this.queryParameters["partNumber"] = partNumber.ToString();
  84. }
  85. try
  86. {
  87. this.queryParameters.Add("uploadId", uploadId);
  88. }
  89. catch (ArgumentException)
  90. {
  91. this.queryParameters["uploadId"] = uploadId;
  92. }
  93. }
  94. protected override void InteranlUpdateHeaders()
  95. {
  96. try
  97. {
  98. this.headers.Add(CosRequestHeaderKey.X_COS_COPY_SOURCE, copySourceStruct.GetCopySouce());
  99. }
  100. catch (ArgumentException)
  101. {
  102. this.headers[CosRequestHeaderKey.X_COS_COPY_SOURCE] = copySourceStruct.GetCopySouce();
  103. }
  104. }
  105. }
  106. }