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

@uppy/aws-s3-multipart: fix the chunk size calculation #4508

Merged
merged 8 commits into from
Jun 19, 2023
Merged
Changes from 4 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
17 changes: 10 additions & 7 deletions packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ class MultipartUploader {
? this.#shouldUseMultipart(this.#file)
: Boolean(this.#shouldUseMultipart)

if (shouldUseMultipart) {
const desiredChunkSize = this.options.getChunkSize(this.#data)
// at least 5MB per request, at most 10k requests
const minChunkSize = Math.max(5 * MB, Math.ceil(fileSize / 10000))
const chunkSize = Math.max(desiredChunkSize, minChunkSize)

const arraySize = Math.ceil(fileSize / chunkSize)
if (shouldUseMultipart && fileSize > 5 * MB) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the file size is 3MB, it will use a single part because of this condition.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay makes sense. Can we make 10_000 and 5 * MB global variables (or class properties). Something like maxMultipartParts and minPartSize?

Can we also add some docs above #initChunks that explains why we need to do these things?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we pull this login out into a function and make a unit test for the different file sizes and expected chunksizes?

// At least 5MB per request:
let chunkSize = Math.max(this.options.getChunkSize(this.#data), 5 * MB)
let arraySize = Math.floor(fileSize / chunkSize)

// At most 10k requests per file:
if (arraySize > 10_000) {
arraySize = 10_000
chunkSize = fileSize / 10_000
}
this.#chunks = Array(arraySize)

for (let i = 0, j = 0; i < fileSize; i += chunkSize, j++) {
Expand Down