From 54da58cbebaa85ce50662cd796f40f191252860a Mon Sep 17 00:00:00 2001 From: Pawel Pisarzewski Date: Wed, 26 Nov 2025 13:23:42 +0100 Subject: [PATCH] Allow passing an object ACL in Put operations --- s3.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/s3.go b/s3.go index 415c884..f18d05d 100644 --- a/s3.go +++ b/s3.go @@ -26,6 +26,7 @@ const ( type Store struct { api *s3.Client readPartSize int64 + putACL *types.ObjectCannedACL } // NewStore returns a Store given the input options. @@ -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{ @@ -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)