Skip to content

Commit

Permalink
Merge pull request #365 from databacker/remove-leading-slash
Browse files Browse the repository at this point in the history
ensure that S3 Push does not double-slash at beginning
  • Loading branch information
deitch authored Nov 3, 2024
2 parents 2aafa42 + edad5b4 commit 3f3f9c5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 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,14 @@ 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 3f3f9c5

Please sign in to comment.