Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bobgroup-go-utils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bob Public Utils
bobgroup-go-utils
Commits
f0c97314
Commit
f0c97314
authored
3 years ago
by
Ruaan Burger
Browse files
Options
Downloads
Patches
Plain Diff
Add param to apply content disposition header to s3 downloads
parent
503fc952
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!20
Add param to apply content disposition header to s3 downloads
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
s3/s3.go
+10
-5
10 additions, 5 deletions
s3/s3.go
with
10 additions
and
5 deletions
s3/s3.go
+
10
−
5
View file @
f0c97314
...
@@ -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
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment