-
Notifications
You must be signed in to change notification settings - Fork 2.1k
@uppy/aws-s3: fix server generated keys not getting returned #6498
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
base: main
Are you sure you want to change the base?
Changes from all commits
eafeb50
a66df15
d53b725
fb9f9bf
f498c19
c502812
343db50
8aee502
bdb7319
c50381b
b279efb
24e96ee
da3f621
83220ee
ac1c708
bb7af70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@uppy/aws-s3": minor | ||
| --- | ||
|
|
||
| `signRequest` can now return the object key it signed for, as `key` next to `url`. When a signing server stores the object under a different key than the one Uppy proposed (a directory prefix, a server-generated name), returning `{ url, key }` from the request that creates the upload, the single-part `PUT`, or the multipart create, makes Uppy use that key for the rest of the upload and report it in `upload-success`. Previously the client-generated key was reported even when the server had stored the object elsewhere (#6496). | ||
|
|
||
| `key` is optional. Signers that return only `{ url }` are unchanged. Requests that carry an `uploadId` must be signed for the key they receive; a `key` returned on those requests is ignored. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ import * as U from './utils.js' | |||||
| * method: 'POST', | ||||||
| * body: JSON.stringify({ method, key, uploadId, partNumber }), | ||||||
| * }); | ||||||
| * return resp.json(); // { url } | ||||||
| * return resp.json(); // { url } or { url, key } | ||||||
| * }, | ||||||
| * }); | ||||||
| * | ||||||
|
|
@@ -185,7 +185,7 @@ class S3mini extends S3Client { | |||||
| }: IT.PutObjectParams) { | ||||||
| this._checkKey(key) | ||||||
|
|
||||||
| const { xhr, url } = await this.request({ | ||||||
| const { xhr, url, signedKey } = await this.request({ | ||||||
| request: { method: 'PUT', key }, | ||||||
| data, | ||||||
| onProgress, | ||||||
|
|
@@ -196,7 +196,7 @@ class S3mini extends S3Client { | |||||
| return { | ||||||
| location: U.removeQueryString(url), | ||||||
| etag: U.sanitizeETag(xhr.getResponseHeader('etag')), | ||||||
| key, | ||||||
| key: signedKey, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -212,7 +212,7 @@ class S3mini extends S3Client { | |||||
| throw new TypeError(`${C.ERROR_PREFIX}fileType must be a string`) | ||||||
| } | ||||||
|
|
||||||
| const { xhr } = await this.request({ | ||||||
| const { xhr, signedKey } = await this.request({ | ||||||
| request: { method: 'POST', key }, | ||||||
| contentType: fileType, | ||||||
| signal, | ||||||
|
|
@@ -231,7 +231,7 @@ class S3mini extends S3Client { | |||||
| const uploadId = uploadResult.uploadId || uploadResult.UploadId | ||||||
|
|
||||||
| if (uploadId && typeof uploadId === 'string') { | ||||||
| return { uploadId, key } | ||||||
| return { uploadId, key: signedKey } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -297,7 +297,7 @@ class S3mini extends S3Client { | |||||
| signal?: AbortSignal | ||||||
| contentType?: string | ||||||
| shouldRetryCredentials?: boolean | ||||||
| }): Promise<{ xhr: XMLHttpRequest; url: string }> { | ||||||
| }): Promise<{ xhr: XMLHttpRequest; url: string; signedKey: string }> { | ||||||
| // Wait for online before starting | ||||||
| await this.waitForOnline(signal) | ||||||
|
|
||||||
|
|
@@ -307,7 +307,7 @@ class S3mini extends S3Client { | |||||
| } | ||||||
|
|
||||||
| try { | ||||||
| const { url } = await this.signRequest(request) | ||||||
| const { url, key: signedKey } = await this.signRequest(request) | ||||||
|
|
||||||
| const xhr = await this.xhr({ | ||||||
| url, | ||||||
|
|
@@ -318,7 +318,7 @@ class S3mini extends S3Client { | |||||
| contentType, | ||||||
| }) | ||||||
|
|
||||||
| return { xhr, url } | ||||||
| return { xhr, url, signedKey: signedKey || request.key } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
i don't like that it means two things, does it need to?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it needs to, because what if the signer doesn't returns the key it has signed in it's response ? then we'll use the client generated key
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intuitively I feel like Michael’s comment makes sense, but I will leave it to you both, as you have more experience with this project.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand why this is confusing, naming is bad here, we will fix this in another PR, already discussed on call. |
||||||
| } catch (err: unknown) { | ||||||
| // NetworkError or errors with attached XHR (from onAfterResponse throws) | ||||||
| if ( | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the directive which we need add in our docs, sadly this wasn't the case previously, before the rewrite we used to return the key from the server