From 6646ad441313bae393277553a65846d3d5094e36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Sequeda=20Gonz=C3=A1lez?= Date: Wed, 18 Sep 2024 19:30:38 -0400 Subject: [PATCH] Fixed #2000 - Add support for "starts-with" in user-metadata post policy condition. --- 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() {