diff --git a/s3/s3.go b/s3/s3.go index c086f6836bf4268920d15040a9c6b0bbdc119116..478d1badd7339b9012f46fd6f00962330685a013 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -28,9 +28,10 @@ type S3UploadResponse struct { } type S3UploadSettings struct { - MimeType MIMEType - RetrieveSignedUrl bool - ExpiryDuration *time.Duration + MimeType MIMEType + RetrieveSignedUrl bool + ExpiryDuration *time.Duration + AddContentDisposition bool } type MIMEType string @@ -121,7 +122,14 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str } if settings.RetrieveSignedUrl { - return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour) + var headers map[string]string + if settings.AddContentDisposition { + headers = map[string]string{ + "content-disposition": "attachment; filename=\"" + fileName + "\"", + } + } + + return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour, headers) } return "", nil @@ -146,11 +154,18 @@ func (s SessionWithHelpers) UploadWith1DayExpiry(data []byte, bucket, fileName s } // 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) (string, error) { +func (s SessionWithHelpers) GetSignedDownloadURL(bucket string, fileName string, duration time.Duration, headers ...map[string]string) (string, error) { getInput := &s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(fileName), } + + if headers != nil { + if value, exists := headers[0]["content-disposition"]; exists { + getInput.ResponseContentDisposition = &value + } + } + getRequest, _ := s.S3Session.GetObjectRequest(getInput) fileExists, err := s.FileExists(bucket, fileName)