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

Add param to apply content disposition header to s3 downloads

parent 503fc952
Branches
Tags
1 merge request!20Add param to apply content disposition header to s3 downloads
...@@ -31,6 +31,7 @@ type S3UploadSettings struct { ...@@ -31,6 +31,7 @@ type S3UploadSettings struct {
MimeType MIMEType MimeType MIMEType
RetrieveSignedUrl bool RetrieveSignedUrl bool
ExpiryDuration *time.Duration ExpiryDuration *time.Duration
AddContentDisposition bool
} }
type MIMEType string type MIMEType string
...@@ -121,7 +122,7 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str ...@@ -121,7 +122,7 @@ func (s SessionWithHelpers) UploadWithSettings(data []byte, bucket, fileName str
} }
if settings.RetrieveSignedUrl { if settings.RetrieveSignedUrl {
return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour) return s.GetSignedDownloadURL(bucket, fileName, 24*time.Hour, settings.AddContentDisposition)
} }
return "", nil return "", nil
...@@ -146,7 +147,7 @@ func (s SessionWithHelpers) UploadWith1DayExpiry(data []byte, bucket, fileName s ...@@ -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. // 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{ getInput := &s3.GetObjectInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(fileName), Key: aws.String(fileName),
...@@ -162,6 +163,10 @@ func (s SessionWithHelpers) GetSignedDownloadURL(bucket string, fileName string, ...@@ -162,6 +163,10 @@ func (s SessionWithHelpers) GetSignedDownloadURL(bucket string, fileName string,
return "", errors.Error("File does not exist") return "", errors.Error("File does not exist")
} }
if addContentDisposition {
getRequest.HTTPRequest.Header.Set("content-disposition", "attachment; filename=\""+fileName+"\"")
}
return getRequest.Presign(duration) 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