PutObjectACLRequest.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /// 设置 对象 的ACL
  11. /// <see href="https://cloud.tencent.com/document/product/436/7748"/>
  12. /// </summary>
  13. public sealed class PutObjectACLRequest : ObjectRequest
  14. {
  15. public PutObjectACLRequest(string bucket, string key)
  16. : base(bucket, key)
  17. {
  18. this.method = CosRequestMethod.PUT;
  19. this.queryParameters.Add("acl", null);
  20. }
  21. /// <summary>
  22. /// 定义 Object 的 acl 属性。有效值:private,public-read-write,public-read;默认值:private
  23. /// <see href="Common.CosACL"/>
  24. /// </summary>
  25. /// <param name="cosACL"></param>
  26. public void SetCosACL(string cosACL)
  27. {
  28. if (cosACL != null)
  29. {
  30. SetRequestHeader(CosRequestHeaderKey.X_COS_ACL, cosACL);
  31. }
  32. }
  33. /// <summary>
  34. /// 定义 Object 的 acl 属性。有效值:private,public-read-write,public-read;默认值:private
  35. /// <see href="Common.CosACL"/>
  36. /// </summary>
  37. /// <param name="cosACL"></param>
  38. public void SetCosACL(CosACL cosACL)
  39. {
  40. SetCosACL(EnumUtils.GetValue(cosACL));
  41. }
  42. /// <summary>
  43. /// 赋予被授权者读的权限
  44. /// <see href="Model.Tag.GrantAccount"/>
  45. /// </summary>
  46. /// <param name="grantAccount"></param>
  47. public void SetXCosGrantRead(GrantAccount grantAccount)
  48. {
  49. if (grantAccount != null)
  50. {
  51. SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_READ, grantAccount.GetGrantAccounts());
  52. }
  53. }
  54. /// <summary>
  55. /// 赋予被授权者所有的权限
  56. /// <see href="Model.Tag.GrantAccount"/>
  57. /// </summary>
  58. /// <param name="grantAccount"></param>
  59. public void SetXCosReadWrite(GrantAccount grantAccount)
  60. {
  61. if (grantAccount != null)
  62. {
  63. SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_FULL_CONTROL, grantAccount.GetGrantAccounts());
  64. }
  65. }
  66. }
  67. }