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: resolve all headers on response #5195

Merged
merged 4 commits into from
May 28, 2024
Merged

Conversation

Murderlon
Copy link
Member

Closes #5138

@Murderlon Murderlon requested a review from aduh95 May 23, 2024 10:05
@Murderlon Murderlon self-assigned this May 23, 2024
Copy link
Contributor

github-actions bot commented May 23, 2024

Diff output files
diff --git a/packages/@uppy/aws-s3-multipart/lib/index.js b/packages/@uppy/aws-s3-multipart/lib/index.js
index aef977f..3b48db2 100644
--- a/packages/@uppy/aws-s3-multipart/lib/index.js
+++ b/packages/@uppy/aws-s3-multipart/lib/index.js
@@ -489,7 +489,7 @@ export default class AwsS3Multipart extends BasePlugin {
         };
         reject(error);
       });
-      xhr.addEventListener("load", ev => {
+      xhr.addEventListener("load", () => {
         cleanup();
         if (xhr.status === 403 && xhr.responseText.includes("<Message>Request has expired</Message>")) {
           const error = new Error("Request has expired");
@@ -507,8 +507,20 @@ export default class AwsS3Multipart extends BasePlugin {
           loaded: size,
           lengthComputable: true,
         });
-        const etag = xhr.getResponseHeader("ETag");
-        const location = xhr.getResponseHeader("Location");
+        const arr = xhr.getAllResponseHeaders().trim().split(/[\r\n]+/);
+        const headersMap = {
+          __proto__: null,
+        };
+        for (const line of arr) {
+          const parts = line.split(": ");
+          const header = parts.shift();
+          const value = parts.join(": ");
+          headersMap[header] = value;
+        }
+        const {
+          etag,
+          location,
+        } = headersMap;
         if (method.toUpperCase() === "POST" && location === null) {
           console.warn(
             "AwsS3/Multipart: Could not read the Location header. This likely means CORS is not configured correctly on the S3 Bucket. See https://uppy.io/docs/aws-s3-multipart#S3-Bucket-Configuration for instructions.",
@@ -524,12 +536,8 @@ export default class AwsS3Multipart extends BasePlugin {
         }
         onComplete == null || onComplete(etag);
         resolve({
+          ...headersMap,
           ETag: etag,
-          ...(location
-            ? {
-              location,
-            }
-            : undefined),
         });
       });
       xhr.addEventListener("error", ev => {

Co-authored-by: Antoine du Hamel <[email protected]>
@Murderlon Murderlon merged commit 7d2ac77 into main May 28, 2024
17 checks passed
@Murderlon Murderlon deleted the aws-resolve-headers branch May 28, 2024 07:54
github-actions bot added a commit that referenced this pull request Jun 4, 2024
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3-multipart |  3.12.0 | @uppy/webcam           |   3.4.2 |
| @uppy/core             |  3.12.0 | uppy                   |  3.26.0 |
| @uppy/transloadit      |   3.7.0 |                        |         |

- meta: remove Companion's `prepublishOnly` (Mikael Finstad / #5220)
- docs: document clearUploadedFiles (Merlijn Vos / #5204)
- @uppy/webcam: add missing types for `recordedVideo` (Antoine du Hamel / #5208)
- @uppy/core: check capabilities in clearUploadedFiles (Merlijn Vos / #5201)
- @uppy/core: PartialTree - change the `maxTotalFileSize` error (Evgenia Karunus / #5203)
- @uppy/transloadit: remove `updateNumberOfFilesInAssembly` (Merlijn Vos / #5202)
- @uppy/aws-s3: resolve all headers on response (Merlijn Vos / #5195)
- docs: Improve provider docs: OneDrive (Evgenia Karunus / #5196)
aduh95 added a commit to aduh95/uppy that referenced this pull request Jun 4, 2024
Co-authored-by: Antoine du Hamel <[email protected]>
aduh95 added a commit to aduh95/uppy that referenced this pull request Jun 4, 2024
Co-authored-by: Antoine du Hamel <[email protected]>
aduh95 added a commit to aduh95/uppy that referenced this pull request Jun 4, 2024
aduh95 added a commit that referenced this pull request Jun 4, 2024
* Backport #5195 to 4.x

Co-authored-by: Antoine du Hamel <[email protected]>

* fixup! Backport #5195 to 4.x

---------

Co-authored-by: Merlijn Vos <[email protected]>
Murderlon added a commit that referenced this pull request Jun 5, 2024
* 4.x:
  meta: fix AWS test suite (#5229)
  Release: [email protected] (#5225)
  Release: [email protected] (#5223)
  meta: remove Companion's `prepublishOnly` (#5220)
  docs: document clearUploadedFiles (#5204)
  @uppy/webcam: add missing types for `recordedVideo` (#5208)
  @uppy/core: check capabilities in clearUploadedFiles (#5201)
  PartialTree - change the `maxTotalFileSize` error (#5203)
  @uppy/transloadit: remove `updateNumberOfFilesInAssembly` (#5202)
  @uppy/aws-s3: resolve all headers on response (#5195)
  Improve provider docs: OneDrive (#5196)
Murderlon added a commit that referenced this pull request Jun 10, 2024
* main: (262 commits)
  Release: [email protected] (#5223)
  meta: remove Companion's `prepublishOnly` (#5220)
  docs: document clearUploadedFiles (#5204)
  @uppy/webcam: add missing types for `recordedVideo` (#5208)
  @uppy/core: check capabilities in clearUploadedFiles (#5201)
  PartialTree - change the `maxTotalFileSize` error (#5203)
  @uppy/transloadit: remove `updateNumberOfFilesInAssembly` (#5202)
  @uppy/aws-s3: resolve all headers on response (#5195)
  Improve provider docs: OneDrive (#5196)
  Release: [email protected] (#5193)
  @uppy/transloadit: do not cancel assembly when removing all files (#5191)
  @uppy/xhr-upload: fix regression for lowercase HTTP methods (#5179)
  meta: improve changelog generator (#5190)
  Release: [email protected] (#5188)
  @uppy/svelte: do not attempt removing plugin before it's created (#5186)
  Update facebook.mdx
  fixup! @uppy/tus: fix no headers passed to companion if argument is a function (#5182)
  @uppy/tus: fix no headers passed to companion if argument is a function (#5182)
  @uppy/companion: fix google drive gsuite export large size (#5144)
  Improve provider docs: Box & Zoom (#5166)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AWS S3 Uploader] Allow retrieving Object Version ID
3 participants