Skip to content
Snippets Groups Projects
Commit e49205d9 authored by Ruaan Burger's avatar Ruaan Burger
Browse files

Add response content disposition header to s3 url

parent f0c97314
Branches
Tags
1 merge request!20Add param to apply content disposition header to s3 downloads
......@@ -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)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment