Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 7266426

Browse files
authored
service/s3/s3manager: Update S3 Upload Multipart location (#2453)
Updates the Location returned value of S3 Upload's Multipart UploadOutput type to be consistent with single part upload URL. This update also brings the multipart upload Location inline with the S3 object URLs created by the SDK Fix #1385
1 parent 7cb6cf9 commit 7266426

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

service/s3/s3manager/upload.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/aws/aws-sdk-go/aws/awserr"
1212
"github.com/aws/aws-sdk-go/aws/awsutil"
1313
"github.com/aws/aws-sdk-go/aws/client"
14+
"github.com/aws/aws-sdk-go/aws/credentials"
1415
"github.com/aws/aws-sdk-go/aws/request"
1516
"github.com/aws/aws-sdk-go/service/s3"
1617
"github.com/aws/aws-sdk-go/service/s3/s3iface"
@@ -593,8 +594,18 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker, firstPart []byte) (*Uploa
593594
uploadID: u.uploadID,
594595
}
595596
}
597+
598+
// Create a presigned URL of the S3 Get Object in order to have parity with
599+
// single part upload.
600+
getReq, _ := u.cfg.S3.GetObjectRequest(&s3.GetObjectInput{
601+
Bucket: u.in.Bucket,
602+
Key: u.in.Key,
603+
})
604+
getReq.Config.Credentials = credentials.AnonymousCredentials
605+
uploadLocation, _, _ := getReq.PresignRequest(1)
606+
596607
return &UploadOutput{
597-
Location: aws.StringValue(complete.Location),
608+
Location: uploadLocation,
598609
VersionID: complete.VersionId,
599610
UploadID: u.uploadID,
600611
}, nil

service/s3/s3manager/upload_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func TestUploadOrderMulti(t *testing.T) {
104104

105105
resp, err := u.Upload(&s3manager.UploadInput{
106106
Bucket: aws.String("Bucket"),
107-
Key: aws.String("Key"),
107+
Key: aws.String("Key - value"),
108108
Body: bytes.NewReader(buf12MB),
109109
ServerSideEncryption: aws.String("aws:kms"),
110110
SSEKMSKeyId: aws.String("KmsId"),
@@ -120,8 +120,8 @@ func TestUploadOrderMulti(t *testing.T) {
120120
t.Errorf("Expected %v, but received %v", expected, *ops)
121121
}
122122

123-
if "https://location" != resp.Location {
124-
t.Errorf("Expected %q, but received %q", "https://location", resp.Location)
123+
if e, a := `https://s3.mock-region.amazonaws.com/Bucket/Key%20-%20value`, resp.Location; e != a {
124+
t.Errorf("Expected %q, but received %q", e, a)
125125
}
126126

127127
if "UPLOAD-ID" != resp.UploadID {
@@ -282,7 +282,7 @@ func TestUploadOrderSingle(t *testing.T) {
282282
mgr := s3manager.NewUploaderWithClient(s)
283283
resp, err := mgr.Upload(&s3manager.UploadInput{
284284
Bucket: aws.String("Bucket"),
285-
Key: aws.String("Key"),
285+
Key: aws.String("Key - value"),
286286
Body: bytes.NewReader(buf2MB),
287287
ServerSideEncryption: aws.String("aws:kms"),
288288
SSEKMSKeyId: aws.String("KmsId"),
@@ -297,8 +297,8 @@ func TestUploadOrderSingle(t *testing.T) {
297297
t.Errorf("Expected %v, but received %v", vals, *ops)
298298
}
299299

300-
if len(resp.Location) == 0 {
301-
t.Error("Expected Location to not be empty")
300+
if e, a := `https://s3.mock-region.amazonaws.com/Bucket/Key%20-%20value`, resp.Location; e != a {
301+
t.Errorf("Expected %q, but received %q", e, a)
302302
}
303303

304304
if e := "VERSION-ID"; e != *resp.VersionID {

0 commit comments

Comments
 (0)