From a11e1ad20cc3a7441611354bc690bc8a05616f21 Mon Sep 17 00:00:00 2001
From: James Page <james@uafrica.com>
Date: Wed, 3 Aug 2022 11:09:24 +0200
Subject: [PATCH] #26 Clarified purpose of expiry duration and added it back to
 `UploadWithSettings`

---
 s3/s3.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/s3/s3.go b/s3/s3.go
index 64c319e..11c9c7a 100644
--- a/s3/s3.go
+++ b/s3/s3.go
@@ -30,7 +30,7 @@ type S3UploadResponse struct {
 type S3UploadSettings struct {
 	MimeType              MIMEType
 	RetrieveSignedUrl     bool
-	ExpiryDuration        *time.Duration
+	ExpiryDuration        *time.Duration // Used to set expiry datetime of download links. NB: does not affect deletion of object from S3 bucket.
 	AddContentDisposition bool
 	FileName              string
 }
@@ -112,6 +112,12 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str
 		Body:        bytes.NewReader(data),
 	}
 
+	// This sets the expiry date of the download link, not the deletion date of the object in the bucket.
+	if settings.ExpiryDuration != nil {
+		expiry := time.Now().Add(*settings.ExpiryDuration)
+		putInput.Expires = &expiry
+	}
+
 	_, err := s.S3Session.PutObject(putInput)
 	if err != nil {
 		return "", err
-- 
GitLab