From 7d712b5e64d1cf8b91e29cb9d130bb32ed988111 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Thu, 30 May 2024 03:17:59 +0800 Subject: [PATCH] feat: support tags for postPolicy Upload (#1967) --- post-policy.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/post-policy.go b/post-policy.go index 3f4881e82c..f6dbbf7f6e 100644 --- a/post-policy.go +++ b/post-policy.go @@ -19,12 +19,14 @@ package minio import ( "encoding/base64" + "errors" "fmt" "net/http" "strings" "time" "github.com/minio/minio-go/v7/pkg/encrypt" + "github.com/minio/minio-go/v7/pkg/tags" ) // expirationDateFormat date format for expiration key in json policy. @@ -152,6 +154,27 @@ func (p *PostPolicy) SetCondition(matchType, condition, value string) error { return errInvalidArgument("Invalid condition in policy") } +// SetTagging - Sets tagging for the object for this policy based upload. +func (p *PostPolicy) SetTagging(tagging string) error { + if strings.TrimSpace(tagging) == "" || tagging == "" { + return errInvalidArgument("No tagging specified.") + } + _, err := tags.ParseObjectXML(strings.NewReader(tagging)) + if err != nil { + return errors.New("The XML you provided was not well-formed or did not validate against our published schema.") //nolint + } + policyCond := policyCondition{ + matchType: "eq", + condition: "$tagging", + value: tagging, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData["tagging"] = tagging + return nil +} + // SetContentType - Sets content-type of the object for this policy // based upload. func (p *PostPolicy) SetContentType(contentType string) error {