浏览代码

@uppy/aws-s3: default to multipart depending on the size of input (#5076)

Antoine du Hamel 1 年之前
父节点
当前提交
24a306fddc
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 7 0
      packages/@uppy/aws-s3/src/index.test.ts
  2. 3 5
      packages/@uppy/aws-s3/src/index.ts

+ 7 - 0
packages/@uppy/aws-s3/src/index.test.ts

@@ -108,6 +108,7 @@ describe('AwsS3Multipart', () => {
     beforeEach(() => {
       core = new Core<any, Body>()
       core.use(AwsS3Multipart, {
+        shouldUseMultipart: true,
         limit: 0,
         createMultipartUpload: vi.fn(() => {
           return {
@@ -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
@@ -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(() => {
@@ -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' })),
@@ -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,
@@ -511,6 +516,7 @@ describe('AwsS3Multipart', () => {
       })
 
       core = new Core<any, Body>().use(AwsS3Multipart, {
+        shouldUseMultipart: true,
         createMultipartUpload,
         signPart: signPartWithAbort,
         listParts,
@@ -580,6 +586,7 @@ describe('AwsS3Multipart', () => {
       })
 
       core = new Core<any, Body>().use(AwsS3Multipart, {
+        shouldUseMultipart: true,
         createMultipartUpload,
         signPart: signPartWithPause,
         listParts,

+ 3 - 5
packages/@uppy/aws-s3/src/index.ts

@@ -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>>
@@ -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)