GetObjectBytesRequest.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using COSXML.Common;
  2. using System;
  3. namespace COSXML.Model.Object
  4. {
  5. public sealed class GetObjectBytesRequest : ObjectRequest
  6. {
  7. /// <summary>
  8. /// 下载进度回调
  9. /// </summary>
  10. private COSXML.Callback.OnProgressCallback progressCallback;
  11. public GetObjectBytesRequest(string bucket, string key) : base(bucket, key)
  12. {
  13. this.method = CosRequestMethod.GET;
  14. }
  15. /// <summary>
  16. /// 下载进度回调
  17. /// </summary>
  18. /// <param name="progressCallback"></param>
  19. public void SetCosProgressCallback(COSXML.Callback.OnProgressCallback progressCallback)
  20. {
  21. this.progressCallback = progressCallback;
  22. }
  23. internal COSXML.Callback.OnProgressCallback GetCosProgressCallback()
  24. {
  25. return progressCallback;
  26. }
  27. /// <summary>
  28. /// 下载内容范围
  29. /// </summary>
  30. /// <param name="start"></param>
  31. /// <param name="end"></param>
  32. public void SetRange(long start, long end)
  33. {
  34. if (start < 0)
  35. {
  36. return;
  37. }
  38. if (end < start)
  39. {
  40. end = -1;
  41. }
  42. SetRequestHeader(CosRequestHeaderKey.RANGE, String.Format("bytes={0}-{1}", start,
  43. (end == -1 ? "" : end.ToString())));
  44. }
  45. /// <summary>
  46. /// 下载内容的起始偏移量
  47. /// </summary>
  48. /// <param name="start"></param>
  49. public void SetRange(long start)
  50. {
  51. SetRange(start, -1);
  52. }
  53. /// <summary>
  54. /// 下载特定版本的对象
  55. /// </summary>
  56. /// <param name="versionId"></param>
  57. public void SetVersionId(string versionId)
  58. {
  59. if (versionId != null)
  60. {
  61. SetQueryParameter(CosRequestHeaderKey.VERSION_ID, versionId);
  62. }
  63. }
  64. }
  65. }