PutObjectTaggingRequest.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using COSXML.Common;
  5. using COSXML.Utils;
  6. using COSXML.Model.Tag;
  7. namespace COSXML.Model.Object
  8. {
  9. /// <summary>
  10. /// 设置对象标签
  11. /// <see href="https://cloud.tencent.com/document/product/436/42997"/>
  12. /// </summary>
  13. public sealed class PutObjectTaggingRequest : ObjectRequest
  14. {
  15. private Tagging tagging;
  16. public PutObjectTaggingRequest(string bucket, string key)
  17. : base(bucket, key)
  18. {
  19. this.method = CosRequestMethod.PUT;
  20. this.queryParameters.Add("tagging", null);
  21. this.tagging = new Tagging();
  22. }
  23. /// <summary>
  24. /// 向指定版本的对象添加标签
  25. /// </summary>
  26. /// <param name="versionId"></param>
  27. public void SetVersionId(string versionId)
  28. {
  29. if (versionId != null)
  30. {
  31. SetQueryParameter(CosRequestHeaderKey.VERSION_ID, versionId);
  32. }
  33. }
  34. /// <summary>
  35. /// 向标签键值对增加内容
  36. /// </summary>
  37. /// <param name="key"></param>
  38. /// <param name="value"></param>
  39. public void AddTag(string key, string value)
  40. {
  41. this.tagging.AddTag(key, value);
  42. }
  43. public override Network.RequestBody GetRequestBody()
  44. {
  45. return GetXmlRequestBody(tagging);
  46. }
  47. }
  48. }