Skip to content

Commit

Permalink
@uppy/aws-s3-multipart: add support for allowedMetaFields option (t…
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Jan 4, 2023
1 parent 83ac000 commit b4abc36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
14 changes: 7 additions & 7 deletions packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/aws-s3-multipart/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion website/src/docs/aws-s3-multipart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit b4abc36

Please sign in to comment.