diff --git a/s3/s3.go b/s3/s3.go index c086f6836bf4268920d15040a9c6b0bbdc119116..e41a27c1c3ebc3a81480234b16e5ca74c66c1fd7 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,7 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str } if settings.RetrieveSignedUrl { - return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour) + return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour, settings.AddContentDisposition) } return "", nil @@ -146,7 +147,7 @@ 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, addContentDisposition bool) (string, error) { getInput := &s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(fileName), @@ -162,6 +163,10 @@ func (s SessionWithHelpers) GetSignedDownloadURL(bucket string, fileName string, return "", errors.Error("File does not exist") } + if addContentDisposition { + getRequest.HTTPRequest.Header.Set("content-disposition", "attachment; filename=\""+fileName+"\"") + } + return getRequest.Presign(duration) }