Skip to content

Commit

Permalink
fix(lib-storage): fix Location field decoding in Upload class (#5668)
Browse files Browse the repository at this point in the history
  • Loading branch information
ichina committed Jan 11, 2024
1 parent 62c2ec4 commit 59ff8e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/lib-storage/src/Upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ describe(Upload.name, () => {
expect(result.Location).toEqual("https://s3.region.amazonaws.com/example-bucket/example-key");
});

it("should return a Location field with decoded slash symbols", async () => {
const partSize = 1024 * 1024 * 5;
const largeBuffer = Buffer.from("#".repeat(partSize + 10));
const actionParams = { ...params, Body: largeBuffer };
const completeMultipartMockWithLocation = completeMultipartMock.mockResolvedValueOnce({
Location: "https://example-bucket.example-host.com/folder%2Fexample-key",
});
const upload = new Upload({
params: actionParams,
client: new S3({}),
});
const result = (await upload.done()) as CompleteMultipartUploadCommandOutput;
expect(completeMultipartMockWithLocation).toHaveBeenCalledTimes(1);
expect(result.Location).toEqual("https://example-bucket.example-host.com/folder/example-key");
});

it("should upload using multi-part when parts are larger than part size", async () => {
// create a string that's larger than 5MB.
const partSize = 1024 * 1024 * 5;
Expand Down
3 changes: 3 additions & 0 deletions lib/lib-storage/src/Upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ export class Upload extends EventEmitter {
},
};
result = await this.client.send(new CompleteMultipartUploadCommand(uploadCompleteParams));
if (typeof result?.Location === "string" && result.Location.includes("%2F")) {
result.Location = result.Location.replace(/%2F/g, "/");
}
} else {
result = this.singleUploadResult!;
}
Expand Down

0 comments on commit 59ff8e1

Please sign in to comment.