Skip to content

Commit

Permalink
service/s3/s3manager: Update S3 Upload Multipart location
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jasdel committed Jun 14, 2019
1 parent db223f6 commit 2021f5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 11 additions & 1 deletion service/s3/s3manager/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,18 @@ func (u *multiuploader) upload(firstBuf io.ReadSeeker) (*UploadOutput, error) {
uploadID: u.uploadID,
}
}

// Create a presigned URL of the S3 Get Object in order to have parity with
// single part upload.
getReq := u.cfg.S3.GetObjectRequest(&s3.GetObjectInput{
Bucket: u.in.Bucket,
Key: u.in.Key,
})
getReq.Config.Credentials = aws.AnonymousCredentials
uploadLocation, _, _ := getReq.PresignRequest(1)

return &UploadOutput{
Location: aws.StringValue(complete.Location),
Location: uploadLocation,
VersionID: complete.VersionId,
UploadID: u.uploadID,
}, nil
Expand Down
12 changes: 6 additions & 6 deletions service/s3/s3manager/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestUploadOrderMulti(t *testing.T) {

resp, err := u.Upload(&s3manager.UploadInput{
Bucket: aws.String("Bucket"),
Key: aws.String("Key"),
Key: aws.String("Key - value"),
Body: bytes.NewReader(buf12MB),
ServerSideEncryption: s3.ServerSideEncryptionAwsKms,
SSEKMSKeyId: aws.String("KmsId"),
Expand All @@ -120,8 +120,8 @@ func TestUploadOrderMulti(t *testing.T) {
t.Errorf("Expected %v, but received %v", expected, *ops)
}

if "https://location" != resp.Location {
t.Errorf("Expected %q, but received %q", "https://location", resp.Location)
if e, a := `https://endpoint/Bucket/Key%20-%20value`, resp.Location; e != a {
t.Errorf("Expected %q, but received %q", e, a)
}

if "UPLOAD-ID" != resp.UploadID {
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestUploadOrderSingle(t *testing.T) {
mgr := s3manager.NewUploaderWithClient(s)
resp, err := mgr.Upload(&s3manager.UploadInput{
Bucket: aws.String("Bucket"),
Key: aws.String("Key"),
Key: aws.String("Key - value"),
Body: bytes.NewReader(buf2MB),
ServerSideEncryption: s3.ServerSideEncryptionAwsKms,
SSEKMSKeyId: aws.String("KmsId"),
Expand All @@ -297,8 +297,8 @@ func TestUploadOrderSingle(t *testing.T) {
t.Errorf("Expected %v, but received %v", vals, *ops)
}

if len(resp.Location) == 0 {
t.Error("Expected Location to not be empty")
if e, a := `https://endpoint/Bucket/Key%20-%20value`, resp.Location; e != a {
t.Errorf("Expected %q, but received %q", e, a)
}

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

0 comments on commit 2021f5c

Please sign in to comment.