Kaynağa Gözat

@uppy/aws-s3-multipart: add support for `allowedMetaFields` option (#4215)

Antoine du Hamel 2 yıl önce
ebeveyn
işleme
b4abc36c7e

+ 7 - 7
packages/@uppy/aws-s3-multipart/src/index.js

@@ -236,6 +236,8 @@ export default class AwsS3Multipart extends BasePlugin {
     this.#client = new RequestClient(uppy, opts)
 
     const defaultOptions = {
+      // TODO: this is currently opt-in for backward compat, switch to opt-out in the next major
+      allowedMetaFields: null,
       limit: 6,
       retryDelays: [0, 1000, 3000, 5000],
       createMultipartUpload: this.createMultipartUpload.bind(this),
@@ -313,13 +315,11 @@ export default class AwsS3Multipart extends BasePlugin {
     this.assertHost('createMultipartUpload')
     throwIfAborted(signal)
 
-    const metadata = {}
-
-    Object.keys(file.meta || {}).forEach(key => {
-      if (file.meta[key] != null) {
-        metadata[key] = file.meta[key].toString()
-      }
-    })
+    const metadata = file.meta ? Object.fromEntries(
+      (this.opts.allowedMetaFields ?? Object.keys(file.meta))
+        .filter(key => file.meta[key] != null)
+        .map(key => [`metadata[${key}]`, String(file.meta[key])]),
+    ) : {}
 
     return this.#client.post('s3/multipart', {
       filename: file.name,

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

@@ -16,6 +16,7 @@ export interface AwsS3MultipartOptions extends PluginOptions {
     companionHeaders?: { [type: string]: string }
     companionUrl?: string
     companionCookiesRule?: string
+    allowedMetaFields?: string[] | null
     getChunkSize?: (file: UppyFile) => number
     createMultipartUpload?: (
       file: UppyFile

+ 8 - 1
website/src/docs/aws-s3-multipart.md

@@ -45,7 +45,6 @@ The maximum amount of chunks to upload simultaneously. You should set the limit
 
 Because HTTP/1.1 limits the number of concurrent requests to one origin to 6, it’s recommended to always set a limit of 6 or smaller for all your uploads, or to not override the default.
 
-
 ### `retryDelays: [0, 1000, 3000, 5000]`
 
 `retryDelays` are the intervals in milliseconds used to retry a failed chunk.
@@ -70,6 +69,14 @@ This will be used by the default implementations of the upload-related functions
 
 This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether to send cookies to [Companion](/docs/companion).
 
+### `allowedMetaFields: null`
+
+Pass an array of field names to limit the metadata fields that will be added to upload as query parameters.
+
+* Set this to `['name']` to only send the `name` field.
+* Set this to `null` (the default) to send _all_ metadata fields.
+* Set this to an empty array `[]` to not send any fields.
+
 ### `getChunkSize(file)`
 
 A function that returns the minimum chunk size to use when uploading the given file.