Skip to content

Commit 3f3f9c5

Browse files
authored
Merge pull request #365 from databacker/remove-leading-slash
ensure that S3 Push does not double-slash at beginning
2 parents 2aafa42 + edad5b4 commit 3f3f9c5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/storage/s3/s3.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88
"os"
99
"path"
10+
"strings"
1011
"time"
1112

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

117+
// S3 always prepends a /, so if it already has one, it would become //
118+
// For some services, that is ok, but for others, it causes issues.
119+
key = strings.TrimPrefix(path.Join(key, target), "/")
120+
116121
// Write the contents of the file to the S3 object
117122
_, err = uploader.Upload(context.TODO(), &s3.PutObjectInput{
118123
Bucket: aws.String(bucket),
119-
Key: aws.String(path.Join(key, target)),
124+
Key: aws.String(key),
120125
Body: f,
121126
})
122127
if err != nil {

0 commit comments

Comments
 (0)