Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chunks back to prepareUploadParts, indexed by partNumber #3520

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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