diff --git a/s3/s3.go b/s3/s3.go index e41a27c1c3ebc3a81480234b16e5ca74c66c1fd7..478d1badd7339b9012f46fd6f00962330685a013 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -122,7 +122,14 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str } if settings.RetrieveSignedUrl { - return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour, settings.AddContentDisposition) + 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 @@ -147,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, addContentDisposition bool) (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) @@ -163,10 +177,6 @@ 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) }