Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
type Store struct {
api *s3.Client
readPartSize int64
putACL *types.ObjectCannedACL
Comment thread
indiependente marked this conversation as resolved.
}

// NewStore returns a Store given the input options.
Expand Down Expand Up @@ -62,6 +63,15 @@ func WithReadPartSize(size int64) func(s *Store) error {
}
}

// WithPutACL uses the provided canned ACL during Put operations.
func WithPutACL(acl types.ObjectCannedACL) func(s *Store) error {
return func(s *Store) error {
s.putACL = &acl

return nil
}
}

// Get returns the content of the file in input reading it from the underlying S3 bucket.
func (s Store) Get(ctx context.Context, prefix, bucketname, filename string) (io.ReadCloser, error) {
objOut, err := s.api.HeadObject(ctx, &s3.HeadObjectInput{
Expand Down Expand Up @@ -142,6 +152,11 @@ func (s Store) Put(ctx context.Context, prefix, bucketname, filename string, r i
Bucket: aws.String(bucketname),
Key: aws.String(prefix + filename),
}

if s.putACL != nil {
input.ACL = *s.putACL
}

resp, err := s.api.CreateMultipartUpload(ctx, input)
if err != nil {
return 0, fmt.Errorf("could not create multipart upload: %w", err)
Expand Down
Loading