Skip to content

Commit

Permalink
@uppy/aws-s3: default to multipart depending on the size of input (#5076
Browse files Browse the repository at this point in the history
)
  • Loading branch information
aduh95 authored Apr 11, 2024
1 parent f6734fe commit 24a306f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 7 additions & 0 deletions packages/@uppy/aws-s3/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('AwsS3Multipart', () => {
beforeEach(() => {
core = new Core<any, Body>()
core.use(AwsS3Multipart, {
shouldUseMultipart: true,
limit: 0,
createMultipartUpload: vi.fn(() => {
return {
Expand Down Expand Up @@ -167,6 +168,7 @@ describe('AwsS3Multipart', () => {
let busySpy
let doneSpy
awsS3Multipart.setOptions({
shouldUseMultipart: true,
retryDelays: [10],
createMultipartUpload: vi.fn((file) => {
// @ts-expect-error protected property
Expand Down Expand Up @@ -250,6 +252,7 @@ describe('AwsS3Multipart', () => {

it('retries uploadPartBytes when it fails once', async () => {
const core = new Core<any, Body>().use(AwsS3Multipart, {
shouldUseMultipart: true,
createMultipartUpload,
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
abortMultipartUpload: vi.fn(() => {
Expand Down Expand Up @@ -282,6 +285,7 @@ describe('AwsS3Multipart', () => {

it('calls `upload-error` when uploadPartBytes fails after all retries', async () => {
const core = new Core<any, Body>().use(AwsS3Multipart, {
shouldUseMultipart: true,
retryDelays: [10],
createMultipartUpload,
completeMultipartUpload: vi.fn(async () => ({ location: 'test' })),
Expand Down Expand Up @@ -451,6 +455,7 @@ describe('AwsS3Multipart', () => {

it('preserves file metadata if upload is completed', async () => {
core = new Core<any, Body>().use(AwsS3Multipart, {
shouldUseMultipart: true,
createMultipartUpload,
signPart,
listParts,
Expand Down Expand Up @@ -511,6 +516,7 @@ describe('AwsS3Multipart', () => {
})

core = new Core<any, Body>().use(AwsS3Multipart, {
shouldUseMultipart: true,
createMultipartUpload,
signPart: signPartWithAbort,
listParts,
Expand Down Expand Up @@ -580,6 +586,7 @@ describe('AwsS3Multipart', () => {
})

core = new Core<any, Body>().use(AwsS3Multipart, {
shouldUseMultipart: true,
createMultipartUpload,
signPart: signPartWithPause,
listParts,
Expand Down
8 changes: 3 additions & 5 deletions packages/@uppy/aws-s3/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ const defaultOptions = {
allowedMetaFields: true,
limit: 6,
getTemporarySecurityCredentials: false as any,
shouldUseMultipart: ((file: UppyFile<any, any>) =>
file.size !== 0) as any as true, // TODO: Switch default to:
// eslint-disable-next-line no-bitwise
// shouldUseMultipart: (file) => file.size >> 10 >> 10 > 100,
shouldUseMultipart: ((file: UppyFile<any, any>) =>
// eslint-disable-next-line no-bitwise
(file.size! >> 10) >> 10 > 100) as any as true,
retryDelays: [0, 1000, 3000, 5000],
companionHeaders: {},
} satisfies Partial<AwsS3MultipartOptions<any, any>>
Expand Down Expand Up @@ -337,8 +337,6 @@ export default class AwsS3Multipart<
// We need the `as any` here because of the dynamic default options.
this.type = 'uploader'
this.id = this.opts.id || 'AwsS3Multipart'
// @ts-expect-error TODO: remove unused
this.title = 'AWS S3 Multipart'
// TODO: only initiate `RequestClient` is `companionUrl` is defined.
this.#client = new RequestClient(uppy, opts as any)

Expand Down

0 comments on commit 24a306f

Please sign in to comment.