From 100ddb4f1d095ec2bcb180caea96756abf8a0c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Sequeda=20Gonz=C3=A1lez?= Date: Thu, 19 Sep 2024 09:01:34 -0400 Subject: [PATCH] Fixed #2000 - Add support for "starts-with" in user-metadata post policy condition. (#2001) --- post-policy.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/post-policy.go b/post-policy.go index 3f023704a..19687e027 100644 --- a/post-policy.go +++ b/post-policy.go @@ -301,6 +301,25 @@ func (p *PostPolicy) SetUserMetadata(key, value string) error { return nil } +// SetUserMetadataStartsWith - Set how an user metadata should starts with. +// Can be retrieved through a HEAD request or an event. +func (p *PostPolicy) SetUserMetadataStartsWith(key, value string) error { + if strings.TrimSpace(key) == "" || key == "" { + return errInvalidArgument("Key is empty") + } + headerName := fmt.Sprintf("x-amz-meta-%s", key) + policyCond := policyCondition{ + matchType: "starts-with", + condition: fmt.Sprintf("$%s", headerName), + value: value, + } + if err := p.addNewPolicy(policyCond); err != nil { + return err + } + p.formData[headerName] = value + return nil +} + // SetChecksum sets the checksum of the request. func (p *PostPolicy) SetChecksum(c Checksum) { if c.IsSet() {