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

CompleteMultipartUploadCommand missing IfMatch types #6795

Closed
3 of 4 tasks
DarthCoder117 opened this issue Jan 12, 2025 · 5 comments
Closed
3 of 4 tasks

CompleteMultipartUploadCommand missing IfMatch types #6795

DarthCoder117 opened this issue Jan 12, 2025 · 5 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@DarthCoder117
Copy link

Checkboxes for prior research

Describe the bug

Trying to use CompleteMultipartUploadCommand with conditional requests I noticed the IfMatch and IfNoneMatch fields are visible in the API reference, but not available in the actual package.

I assumed it must be that my SDK is outdated, so I tried updating to the latest version but nothing changed.

I also checked to see that the same issue affects the PutObjectCommand as well.

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/command/CompleteMultipartUploadCommand/
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/command/PutObjectCommand/

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.11.1

Reproduction Steps

Try to instantiate a CompleteMultipartUploadCommand using either IfMatch or IfNoneMatch

new CompleteMultipartUploadCommand({
  Bucket: "some-bucket",
  Key: "some/key",
  UploadId: "1234567890",
  IfNoneMatch: "*",
});

Observed Behavior

You get type errors:

No overload matches this call.
  Overload 1 of 2, '(input: CompleteMultipartUploadCommandInput): CompleteMultipartUploadCommand', gave the following error.
    Object literal may only specify known properties, and 'IfNoneMatch' does not exist in type 'CompleteMultipartUploadCommandInput'.
  Overload 2 of 2, '(__0_0: CompleteMultipartUploadCommandInput): CompleteMultipartUploadCommand', gave the following error.
    Object literal may only specify known properties, and 'IfNoneMatch' does not exist in type 'CompleteMultipartUploadCommandInput'.ts(2769)

Expected Behavior

You shouldn't get type errors.

Possible Solution

No response

Additional Information/Context

I believe this bug was likely not noticed because using a separate input object dodges the type error.

This works fine:

const input = {
  Bucket: "some-bucket",
  Key: "some/key",
  UploadId: "1234567890",
  IfNoneMatch: "*",
};
new CompleteMultipartUploadCommand(input);
@DarthCoder117 DarthCoder117 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 12, 2025
@zshzbh zshzbh self-assigned this Jan 13, 2025
@zshzbh
Copy link
Contributor

zshzbh commented Jan 13, 2025

Hey @DarthCoder117 ,

I can't reproduce this issue and I will post my code&result in another comment.

IfMatch was introduced 2 months ago in 3.700.0, you should be able to use this parameter if you are using @aws-sdk/[email protected]

Here's my suggestion -

Please run the command to reinstall the latest version package and build the application.

rm -rf node_modules/
npm install

Run the app, see if the error persists.

@zshzbh
Copy link
Contributor

zshzbh commented Jan 13, 2025

Code I have -

import { 
	S3Client, 
	CreateMultipartUploadCommand,
	UploadPartCommand,
	CompleteMultipartUploadCommand 
  } from "@aws-sdk/client-s3";
  
  async function performMultipartUpload(bucketName, key, fileData) {
	const s3Client = new S3Client({ region: "us-east-1" });
	let uploadId;
	const uploadedParts = [];
  
	try {
	  // 1. Start the multipart upload to get an upload ID
	  const createResponse = await s3Client.send(new CreateMultipartUploadCommand({
		Bucket: bucketName,
		Key: key
	  }));
	  
	  uploadId = createResponse.UploadId;
	  console.log("Started upload with ID:", uploadId);
  
	  // 2. Upload parts (simplified example)
	  const partSize = 5 * 1024 * 1024; // 5MB minimum size
	  for (let i = 0; i < fileData.length; i += partSize) {
		const chunk = fileData.slice(i, i + partSize);
		const partNumber = Math.floor(i / partSize) + 1;
  
		const uploadResponse = await s3Client.send(new UploadPartCommand({
		  Bucket: bucketName,
		  Key: key,
		  UploadId: uploadId,
		  PartNumber: partNumber,
		  Body: chunk
		}));
  
		uploadedParts.push({
		  PartNumber: partNumber,
		  ETag: uploadResponse.ETag
		});
	  }
  
	  // 3. Complete the multipart upload
	  const completeResponse = await s3Client.send(new CompleteMultipartUploadCommand({
		Bucket: bucketName,
		Key: key,
		UploadId: uploadId,
		MultipartUpload: {
		  Parts: uploadedParts.sort((a, b) => a.PartNumber - b.PartNumber)
		},
		IfNoneMatch: '*'
	  }));
  
	  return completeResponse;
  
	} catch (error) {
	  console.error("Upload failed:", error);
	  throw error;
	}
  }
  
  // Example usage
  const exampleData = Buffer.from("Example file content");
  performMultipartUpload(
	"my-bucket",
	"example.txt",
	exampleData
  )
	.then(result => console.log("Success:", result))
	.catch(error => console.error("Error:", error));
  

result I got

Started upload with ID: zGtJwQwW5lrwumY3s.nIsGAkQKTvIMFg.XXXXX.a3sjHeHomJiy9LtjOH.XXXX
Success: {
  '$metadata': {
    httpStatusCode: 200,
    requestId: 'XXXXx',
    extendedRequestId: 'XXXX/W8WyK+XXXX=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
  },
  ServerSideEncryption: 'AES256',
  Bucket: 'test-s3-xxx-maggie',
  ETag: '"XXXXXXXx-1"',
  Key: 'example.txt',
  Location: 'https://test-s3-xxx-maggie.s3.us-east-1.amazonaws.com/example.txt'
}

And I can see file has been successfully uploaded
Image

@zshzbh zshzbh added p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 13, 2025
@DarthCoder117
Copy link
Author

Just cleared my node_modules and tried again and it works fine now.
I guess it must have been something cache related with our monorepo tooling.
Sorry, false alarm.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants