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: default to multipart depending on the size of input #5076

Merged
merged 2 commits into from
Apr 11, 2024
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
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,
Copy link
Member

Choose a reason for hiding this comment

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

A bit too clever for my taste.

I think this is more clear file.size > 100 * 1024 * 1024

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
Loading