diff --git a/packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts b/packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts index c015633ad9..d349fc6823 100644 --- a/packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts +++ b/packages/@uppy/aws-s3/src/HTTPCommunicationQueue.ts @@ -253,7 +253,7 @@ export class HTTPCommunicationQueue { }).abortOn(signal) let body: FormData | Blob - const data = chunk.getData() + const data = await chunk.getData() if (method.toUpperCase() === 'POST') { const formData = new FormData() Object.entries(fields!).forEach(([key, value]) => @@ -387,7 +387,7 @@ export class HTTPCommunicationQueue { for (;;) { throwIfAborted(signal) - const chunkData = chunk.getData() + const chunkData = await chunk.getData() const { onProgress, onComplete } = chunk let signature diff --git a/packages/@uppy/aws-s3/src/MultipartUploader.ts b/packages/@uppy/aws-s3/src/MultipartUploader.ts index 6f5397a7fd..5dad800c0e 100644 --- a/packages/@uppy/aws-s3/src/MultipartUploader.ts +++ b/packages/@uppy/aws-s3/src/MultipartUploader.ts @@ -7,6 +7,7 @@ const MB = 1024 * 1024 interface MultipartUploaderOptions { getChunkSize?: (file: { size: number }) => number + getChunkData?: (start: number, end: number, opts: { chunkSize: number }) => Promise onProgress?: (bytesUploaded: number, bytesTotal: number) => void onPartComplete?: (part: { PartNumber: number; ETag: string }) => void shouldUseMultipart?: boolean | ((file: UppyFile) => boolean) @@ -33,7 +34,7 @@ const defaultOptions = { } satisfies Partial> export interface Chunk { - getData: () => Blob + getData: () => Promise onProgress: (ev: ProgressEvent) => void onComplete: (etag: string) => void shouldUseMultipart: boolean @@ -146,9 +147,10 @@ class MultipartUploader { const end = Math.min(fileSize, offset + chunkSize) // Defer data fetching/slicing until we actually need the data, because it's slow if we have a lot of files - const getData = () => { + const getData = async () => { const i2 = offset - return this.#data.slice(i2, end) + return this.options.getChunkData ? this.options.getChunkData(i2, end, { chunkSize }) : + this.#data.slice(i2, end) } this.#chunks[j] = { @@ -171,7 +173,7 @@ class MultipartUploader { } else { this.#chunks = [ { - getData: () => this.#data, + getData: async () => this.#data, onProgress: this.#onPartProgress(0), onComplete: this.#onPartComplete(0), shouldUseMultipart,