Skip to content
Snippets Groups Projects
Commit b58e9317 authored by James Page's avatar James Page
Browse files

Merge branch '26-remove-expiryduration-from-s3uploadsettings' into 'main'

Resolve "Remove ExpiryDuration from S3UploadSettings"

See merge request uafrica/go-utils!29
parents 24c633d0 a11e1ad2
Branches
Tags
1 merge request!29Resolve "Remove ExpiryDuration from S3UploadSettings"
......@@ -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,7 @@ 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
......@@ -142,25 +143,6 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str
return "", nil
}
func (s SessionWithHelpers) UploadWith1DayExpiry(data []byte, bucket, fileName string, mimeType MIMEType, shouldDownloadInsteadOfOpen bool) (string, error) {
if mimeType == "" {
mimeType = getTypeForFilename(fileName)
}
expiry := 24 * time.Hour
signedUrl, err := s.UploadWithSettings(data, bucket, fileName, S3UploadSettings{
MimeType: mimeType,
RetrieveSignedUrl: true,
ExpiryDuration: &expiry,
AddContentDisposition: shouldDownloadInsteadOfOpen,
})
if err != nil {
return "", err
}
return signedUrl, nil
}
// GetSignedDownloadURL gets a signed download URL for the duration. If scv is nil, a new session will be created.
func (s SessionWithHelpers) GetSignedDownloadURL(bucket string, fileName string, duration time.Duration, headers ...map[string]string) (string, error) {
getInput := &s3.GetObjectInput{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment