Skip to content

Commit

Permalink
Add chunks back to prepareUploadParts, indexed by partNumber (#3520)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-west-10x authored Mar 2, 2022
1 parent 00d5933 commit d6ebe70
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ class MultipartUploader {
key: this.key,
uploadId: this.uploadId,
partNumbers: candidates.map((index) => index + 1),
chunks: candidates.reduce((chunks, candidate) => ({
...chunks,
// Use the part number as the index
[candidate + 1]: this.chunks[candidate],
}), {}),
}),
})

Expand Down
14 changes: 11 additions & 3 deletions packages/@uppy/aws-s3-multipart/src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,18 @@ describe('AwsS3Multipart', () => {

await core.upload()

function validatePartData ({ partNumbers, chunks }, expected) {
expect(partNumbers).toEqual(expected)
partNumbers.forEach(partNumber => {
expect(chunks[partNumber]).toBeDefined()
})
}

expect(awsS3Multipart.opts.prepareUploadParts.mock.calls.length).toEqual(3)
expect(awsS3Multipart.opts.prepareUploadParts.mock.calls[0][1].partNumbers).toEqual([1, 2, 3, 4, 5])
expect(awsS3Multipart.opts.prepareUploadParts.mock.calls[1][1].partNumbers).toEqual([6, 7, 8])
expect(awsS3Multipart.opts.prepareUploadParts.mock.calls[2][1].partNumbers).toEqual([9, 10])

validatePartData(awsS3Multipart.opts.prepareUploadParts.mock.calls[0][1], [1, 2, 3, 4, 5])
validatePartData(awsS3Multipart.opts.prepareUploadParts.mock.calls[1][1], [6, 7, 8])
validatePartData(awsS3Multipart.opts.prepareUploadParts.mock.calls[2][1], [9, 10])

const completeCall = awsS3Multipart.opts.completeMultipartUpload.mock.calls[0][1]

Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/aws-s3-multipart/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface AwsS3MultipartOptions extends PluginOptions {
) => MaybePromise<AwsS3Part[]>
prepareUploadParts?: (
file: UppyFile,
partData: { uploadId: string; key: string; partNumbers: Array<number> }
partData: { uploadId: string; key: string; partNumbers: Array<number>; chunks: { [k: number]: Blob } }
) => MaybePromise<{ presignedUrls: { [k: number]: string }, headers?: { [k: string]: string } }>
abortMultipartUpload?: (
file: UppyFile,
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/aws-s3-multipart/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { AwsS3Part } from '..'
expectType<string>(partData.uploadId)
expectType<string>(partData.key)
expectType<Array<number>>(partData.partNumbers)
expectType<{ [k: number]: Blob }>(partData.chunks)
return { presignedUrls: {} }
},
abortMultipartUpload (file, opts) {
Expand Down
1 change: 1 addition & 0 deletions website/src/docs/aws-s3-multipart.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ A function that generates a batch of signed URLs for the specified part numbers.
* `uploadId` - The UploadID of this Multipart upload.
* `key` - The object key in the S3 bucket.
* `partNumbers` - An array of indecies of this part in the file (`PartNumber` in S3 terminology). Note that part numbers are _not_ zero-based.
* `chunks` - A Javascript object with the part numbers as keys and the Blob data for each part as the value.

`prepareUploadParts` should return a `Promise` with an `Object` with keys:

Expand Down

0 comments on commit d6ebe70

Please sign in to comment.