From 622734c4aed1fedef3af01f7961363c945577919 Mon Sep 17 00:00:00 2001
From: Johan de Klerk <johan@shiplogic.com>
Date: Mon, 19 Aug 2024 09:19:24 +0200
Subject: [PATCH] Added upload option to GetSignedUploadURL

---
 s3/s3.go | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/s3/s3.go b/s3/s3.go
index b036668..6ce45f8 100644
--- a/s3/s3.go
+++ b/s3/s3.go
@@ -44,6 +44,11 @@ type S3UploadSettings struct {
 	InsertUUID            bool
 }
 
+type UploadURLAdditionalOptions struct {
+	Metadata map[string]string
+	ACL      types.ObjectCannedACL
+}
+
 // Duration constants
 const (
 	S3ExpiryDuration1Day  time.Duration = 24 * time.Hour
@@ -357,7 +362,7 @@ func (s ClientWithHelpers) GetSignedDownloadURL(bucket string, fileName string,
 }
 
 // GetSignedUploadURL gets a signed upload URL for the duration. If scv is nil, a new session will be created.
-func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, duration time.Duration) (string, error) {
+func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, duration time.Duration, uploadOptions ...UploadURLAdditionalOptions) (string, error) {
 	if s.S3Client == nil {
 		return "", ErrorS3ClientNotEstablished
 	}
@@ -367,6 +372,17 @@ func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, du
 		Key:    aws.String(fileName),
 	}
 
+	// Set custom options
+	if uploadOptions != nil && len(uploadOptions) > 0 {
+		uploadOption := uploadOptions[0]
+		if uploadOption.Metadata != nil {
+			putInput.Metadata = uploadOption.Metadata
+		}
+		if uploadOption.ACL != "" {
+			putInput.ACL = types.ObjectCannedACL(uploadOption.ACL)
+		}
+	}
+
 	presignClient := s3.NewPresignClient(s.S3Client)
 	putRequest, err := presignClient.PresignPutObject(context.TODO(), putInput, func(po *s3.PresignOptions) {
 		po.Expires = duration
-- 
GitLab