Skip to content
Snippets Groups Projects
Commit 622734c4 authored by Johan de Klerk's avatar Johan de Klerk
Browse files

Added upload option to GetSignedUploadURL

parent 13df9396
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,11 @@ type S3UploadSettings struct {
InsertUUID bool
}
type UploadURLAdditionalOptions struct {
Metadata map[string]string
ACL types.ObjectCannedACL
}
// Duration constants
const (
S3ExpiryDuration1Day time.Duration = 24 * time.Hour
......@@ -357,7 +362,7 @@ func (s ClientWithHelpers) GetSignedDownloadURL(bucket string, fileName string,
}
// GetSignedUploadURL gets a signed upload URL for the duration. If scv is nil, a new session will be created.
func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, duration time.Duration) (string, error) {
func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, duration time.Duration, uploadOptions ...UploadURLAdditionalOptions) (string, error) {
if s.S3Client == nil {
return "", ErrorS3ClientNotEstablished
}
......@@ -367,6 +372,17 @@ func (s ClientWithHelpers) GetSignedUploadURL(bucket string, fileName string, du
Key: aws.String(fileName),
}
// Set custom options
if uploadOptions != nil && len(uploadOptions) > 0 {
uploadOption := uploadOptions[0]
if uploadOption.Metadata != nil {
putInput.Metadata = uploadOption.Metadata
}
if uploadOption.ACL != "" {
putInput.ACL = types.ObjectCannedACL(uploadOption.ACL)
}
}
presignClient := s3.NewPresignClient(s.S3Client)
putRequest, err := presignClient.PresignPutObject(context.TODO(), putInput, func(po *s3.PresignOptions) {
po.Expires = duration
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment