Skip to content

Commit 2021f5c

Browse files
committed
service/s3/s3manager: Update S3 Upload Multipart location
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 aws#323 V2 Port aws/aws-sdk-go#2453
1 parent db223f6 commit 2021f5c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

service/s3/s3manager/upload.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,18 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) {
583583
uploadID: u.uploadID,
584584
}
585585
}
586+
587+
// Create a presigned URL of the S3 Get Object in order to have parity with
588+
// single part upload.
589+
getReq := u.cfg.S3.GetObjectRequest(&s3.GetObjectInput{
590+
Bucket: u.in.Bucket,
591+
Key: u.in.Key,
592+
})
593+
getReq.Config.Credentials = aws.AnonymousCredentials
594+
uploadLocation, _, _ := getReq.PresignRequest(1)
595+
586596
return &UploadOutput{
587-
Location: aws.StringValue(complete.Location),
597+
Location: uploadLocation,
588598
VersionID: complete.VersionId,
589599
UploadID: u.uploadID,
590600
}, 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: s3.ServerSideEncryptionAwsKms,
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://endpoint/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: s3.ServerSideEncryptionAwsKms,
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://endpoint/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)