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

aws-nodejs-example | Multipart complete api | Throws 400 bad requests. #5328

Open
2 tasks done
jaswindersingh1903 opened this issue Jul 10, 2024 · 5 comments
Open
2 tasks done
Assignees
Labels

Comments

@jaswindersingh1903
Copy link

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

aws-nodejs-example

Steps to reproduce

  1. Download the example https://github.com/transloadit/uppy/tree/main/examples/aws-nodejs
  2. Run the example and enable multipart
  3. Upload a file to test multipart
  4. The last API call 'complete' to merge the chunks returns with an error.
    MalformedXML: The XML you provided was not well-formed or did not validate against our published schema

Expected behavior

the call should go through and merge all the chunks as one file.

Actual behavior

Throws 400 bad requests.
MalformedXML: The XML you provided was not well-formed or did not validate against our published schema

the format that FE serialize generates and send to compalte is incorrect.
the FE send that data in a format that sdk does not support hence the example is not working
The example generate this JSON

{
    "parts": [
      {
        "PartNumber": [ "1", "2", "3" ],
        "content-length": [ "0", "0", "0" ],
        "etag": [
          "\"52f1dde6780de73e2fc459f138a80607\"",
          "\"502a85a77e77718726463b75d0841f8b\"",
          "\"35b45d5727dd19b9907fa524900ee569\""
        ],
        "ETag": [
          "\"52f1dde6780de73e2fc459f138a80607\"",
          "\"502a85a77e77718726463b75d0841f8b\"",
          "\"35b45d5727dd19b9907fa524900ee569\""
        ]
      }
    ]
  }

should be this aq to aws documentation ( https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/command/CompleteMultipartUploadCommand/ )

The Parts:

 [ // CompletedPartList
      { // CompletedPart
        ETag: "STRING_VALUE",
        ChecksumCRC32: "STRING_VALUE",
        ChecksumCRC32C: "STRING_VALUE",
        ChecksumSHA1: "STRING_VALUE",
        ChecksumSHA256: "STRING_VALUE",
        PartNumber: Number("int"),
      },
    ],

it should be like

{
  "Parts": [
    {
      "ETag": "\"52f1dde6780de73e2fc459f138a80607\"",
      "PartNumber": 1
    },
    {
      "ETag": "\"502a85a77e77718726463b75d0841f8b\"",
      "PartNumber": 2
    },
    {
      "ETag": "\"35b45d5727dd19b9907fa524900ee569\"",
      "PartNumber": 3
    }
  ]
}

Also none of the error handling are working
In this error none of the if was trigger to make debugging easy.

   if (typeof key !== 'string') {
        return res
          .status(400)
          .json({
            error:
              's3: the object key must be passed as a query parameter. For example: "?key=abc.jpg"',
          })
      }
      if (!Array.isArray(parts) || !parts.every(isValidPart)) {
        return res
          .status(400)
          .json({
            error: 's3: `parts` must be an array of {ETag, PartNumber} objects.',
          })
      }
@jaswindersingh1903
Copy link
Author

on '/s3/multipart/:uploadId/complete'
I was able to run it using the parser

     const partInfo = req.body.parts[0];
    const parts = partInfo.PartNumber.map((partNumber, index) => ({
        PartNumber: parseInt(partNumber, 10),
        ETag: partInfo.ETag[index]
    }));

    const output = { parts };
     console.log(JSON.stringify(output, null, 2));

@Murderlon
Copy link
Member

Hi, are you willing to contribute to update the example? :)

@jaswindersingh1903
Copy link
Author

Yes, for sure.
Should I create a PR for the same ?

@Murderlon
Copy link
Member

If you found what caused the problem yes feel free to update the aws-nodejs example 👍

@jaswindersingh1903
Copy link
Author

Yes I did, it is the way we format data in complete api.
It not same as aws documentation so it throws error there.
I will update it accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants