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-multipart: fix getUploadParameters option #4465

Merged
merged 3 commits into from
May 24, 2023
Merged
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
24 changes: 12 additions & 12 deletions packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ function throwIfAborted (signal) {
class HTTPCommunicationQueue {
#abortMultipartUpload

#allowedMetaFields

#cache = new WeakMap()

#createMultipartUpload
Expand Down Expand Up @@ -77,9 +75,6 @@ class HTTPCommunicationQueue {
if ('abortMultipartUpload' in options) {
this.#abortMultipartUpload = requests.wrapPromiseFunction(options.abortMultipartUpload)
}
if ('allowedMetaFields' in options) {
this.#allowedMetaFields = options.allowedMetaFields
}
if ('createMultipartUpload' in options) {
this.#createMultipartUpload = requests.wrapPromiseFunction(options.createMultipartUpload, { priority:-1 })
}
Expand Down Expand Up @@ -217,17 +212,12 @@ class HTTPCommunicationQueue {
}

async #nonMultipartUpload (file, chunk, signal) {
const { meta } = file
const { type, name: filename } = meta
const metadata = getAllowedMetadata({ meta, allowedMetaFields: this.#allowedMetaFields, querify: true })

const query = new URLSearchParams({ filename, type, ...metadata })
const {
method = 'post',
url,
fields,
headers,
} = await this.#getUploadParameters(`s3/params?${query}`, { signal }).abortOn(signal)
} = await this.#getUploadParameters(file, { signal }).abortOn(signal)

const formData = new FormData()
Object.entries(fields).forEach(([key, value]) => formData.set(key, value))
Expand Down Expand Up @@ -344,7 +334,7 @@ export default class AwsS3Multipart extends BasePlugin {
completeMultipartUpload: this.completeMultipartUpload.bind(this),
signPart: this.signPart.bind(this),
uploadPartBytes: AwsS3Multipart.uploadPartBytes,
getUploadParameters: (...args) => this.#client.get(...args),
getUploadParameters: this.getUploadParameters.bind(this),
companionHeaders: {},
}

Expand Down Expand Up @@ -462,6 +452,16 @@ export default class AwsS3Multipart extends BasePlugin {
.then(assertServerError)
}

getUploadParameters (file, options) {
const { meta } = file
const { type, name: filename } = meta
const metadata = getAllowedMetadata({ meta, allowedMetaFields: this.opts.allowedMetaFields, querify: true })

const query = new URLSearchParams({ filename, type, ...metadata })

return this.#client.get(`s3/params?${query}`, options)
}

static async uploadPartBytes ({ signature: { url, expires, headers, method = 'PUT' }, body, size = body.size, onProgress, onComplete, signal }) {
throwIfAborted(signal)

Expand Down