Sfoglia il codice sorgente

@uppy/aws-s3: add `shouldUseMultipart` option (#4299)


Co-authored-by: Artur Paikin <artur@arturpaikin.com>
Antoine du Hamel 1 anno fa
parent
commit
c687d85b5f

+ 3 - 0
packages/@uppy/aws-s3-multipart/types/index.d.ts

@@ -45,6 +45,9 @@ export interface AwsS3MultipartOptions extends PluginOptions {
     limit?: number
     shouldUseMultipart?: boolean | ((file: UppyFile) => boolean)
     retryDelays?: number[] | null
+    getUploadParameters?: (
+      file: UppyFile
+    ) => MaybePromise<{ url: string }>
 }
 
 declare class AwsS3Multipart extends BasePlugin<

+ 1 - 0
packages/@uppy/aws-s3/package.json

@@ -23,6 +23,7 @@
     "url": "git+https://github.com/transloadit/uppy.git"
   },
   "dependencies": {
+    "@uppy/aws-s3-multipart": "workspace:^",
     "@uppy/companion-client": "workspace:^",
     "@uppy/utils": "workspace:^",
     "@uppy/xhr-upload": "workspace:^",

+ 6 - 0
packages/@uppy/aws-s3/src/index.js

@@ -26,6 +26,7 @@
  */
 
 import BasePlugin from '@uppy/core/lib/BasePlugin.js'
+import AwsS3Multipart from '@uppy/aws-s3-multipart'
 import { RateLimitedQueue, internalRateLimitedQueue } from '@uppy/utils/lib/RateLimitedQueue'
 import { RequestClient } from '@uppy/companion-client'
 import { filterNonFailedFiles, filterFilesToEmitUploadStarted } from '@uppy/utils/lib/fileFilters'
@@ -112,6 +113,10 @@ export default class AwsS3 extends BasePlugin {
   #uploader
 
   constructor (uppy, opts) {
+    // Opt-in to using the multipart plugin, which is going to be the only S3 plugin as of the next semver.
+    if (opts?.shouldUseMultipart != null) {
+      return new AwsS3Multipart(uppy, opts)
+    }
     super(uppy, opts)
     this.type = 'uploader'
     this.id = this.opts.id || 'AwsS3'
@@ -124,6 +129,7 @@ export default class AwsS3 extends BasePlugin {
       limit: 0,
       allowedMetaFields: [], // have to opt in
       getUploadParameters: this.getUploadParameters.bind(this),
+      shouldUseMultipart: false,
       companionHeaders: {},
     }
 

+ 3 - 7
packages/@uppy/aws-s3/types/index.d.ts

@@ -1,4 +1,5 @@
-import type { PluginOptions, BasePlugin, UppyFile } from '@uppy/core'
+import { AwsS3MultipartOptions } from '@uppy/aws-s3-multipart'
+import type { BasePlugin } from '@uppy/core'
 
 type MaybePromise<T> = T | Promise<T>
 
@@ -9,14 +10,9 @@ export interface AwsS3UploadParameters {
     headers?: { [type: string]: string }
 }
 
-export interface AwsS3Options extends PluginOptions {
-    companionHeaders?: { [type: string]: string }
-    companionUrl?: string
-    getUploadParameters?: (file: UppyFile) => MaybePromise<AwsS3UploadParameters>
-    allowedMetaFields?: string[] | null
+export interface AwsS3Options extends AwsS3MultipartOptions {
     /** @deprecated future versions of this plugin will use the Expires value from the backend */
     timeout?: number
-    limit?: number
 }
 
 declare class AwsS3 extends BasePlugin<AwsS3Options> {}

+ 1 - 0
yarn.lock

@@ -10464,6 +10464,7 @@ __metadata:
   resolution: "@uppy/aws-s3@workspace:packages/@uppy/aws-s3"
   dependencies:
     "@jest/globals": ^29.0.0
+    "@uppy/aws-s3-multipart": "workspace:^"
     "@uppy/companion-client": "workspace:^"
     "@uppy/utils": "workspace:^"
     "@uppy/xhr-upload": "workspace:^"