Skip to content

Commit

Permalink
ensure that S3 Push does not double-slash at beginning
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Deitcher <avi@deitcher.net>
  • Loading branch information
deitch committed Nov 3, 2024
1 parent 2aafa42 commit 9fc37a2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/storage/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/url"
"os"
"path"
"strings"
"time"

"github.com/aws/aws-sdk-go-v2/aws"
Expand Down Expand Up @@ -113,10 +114,15 @@ func (s *S3) Push(target, source string, logger *log.Entry) (int64, error) {
}
defer f.Close()

// S3 always prepends a /, so if it already has one, it would become //
// For some services, that is ok, but for others, it causes issues.
key = strings.TrimPrefix(path.Join(key, target), "/")

// Write the contents of the file to the S3 object

_, err = uploader.Upload(context.TODO(), &s3.PutObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(path.Join(key, target)),
Key: aws.String(key),
Body: f,
})
if err != nil {
Expand Down

0 comments on commit 9fc37a2

Please sign in to comment.