From 1889034b5e2e16e08ec6ce924ac428a69958fa9c Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Tue, 28 May 2024 10:49:52 +0800 Subject: [PATCH 1/3] feat: support tags for postPolicy Upload --- post-policy.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/post-policy.go b/post-policy.go index 3f4881e82c..6d42488e54 100644 --- a/post-policy.go +++ b/post-policy.go @@ -152,6 +152,23 @@ 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.") + } + 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 { From f758d177456caf75f6e77c81a80467ebf5f29cc4 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Wed, 29 May 2024 16:46:06 +0800 Subject: [PATCH 2/3] parse error --- post-policy.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/post-policy.go b/post-policy.go index 6d42488e54..4cc9e24d5e 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. @@ -157,6 +159,10 @@ 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.") + } policyCond := policyCondition{ matchType: "eq", condition: "$tagging", From 7b4f11b1245e461d9014d1ae57e650463feab277 Mon Sep 17 00:00:00 2001 From: jiuker <2818723467@qq.com> Date: Wed, 29 May 2024 16:59:35 +0800 Subject: [PATCH 3/3] nolint --- post-policy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-policy.go b/post-policy.go index 4cc9e24d5e..f6dbbf7f6e 100644 --- a/post-policy.go +++ b/post-policy.go @@ -161,7 +161,7 @@ func (p *PostPolicy) SetTagging(tagging string) error { } _, 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.") + return errors.New("The XML you provided was not well-formed or did not validate against our published schema.") //nolint } policyCond := policyCondition{ matchType: "eq",