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 2 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
21 changes: 15 additions & 6 deletions packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,21 @@ class MultipartUploader {
: 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)
let arraySize, chunkSize
if (fileSize < 5 * MB) {
// At least 5MB per request:
chunkSize = 5 * MB;
arraySize = 1
} else {
chunkSize = Math.max(this.options.getChunkSize(this.#data), 5 * MB)
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