From 3529f97899453ca809e0dd233b208754c32f2420 Mon Sep 17 00:00:00 2001 From: Prakash Date: Tue, 3 Feb 2026 15:18:38 +0530 Subject: [PATCH] fix signature mismatch in @uppy/aws-s3 (#6165) shouldUseMultipart: true was not working due to signature mismatch AI summary : This pull request improves support for specifying the `contentType` during S3 uploads, ensuring that the correct content type is set when generating presigned URLs for both single and multipart uploads. It also updates the client-side and server-side code to handle this new parameter. **Backend and API enhancements:** - Updated the `/s3/presign` endpoint in `index.js` to accept an optional `contentType` parameter and to include it in the S3 `PutObjectCommand` and `CreateMultipartUploadCommand` requests, defaulting to `'application/octet-stream'` if not provided. [[1]](diffhunk://#diff-0c4471088c62917198e1438777b4c7e78fd4d87d450d2a7c78b86b7c647ac97bL360-R360) [[2]](diffhunk://#diff-0c4471088c62917198e1438777b4c7e78fd4d87d450d2a7c78b86b7c647ac97bR384-R391) **Client-side and types improvements:** - Added `contentType` to the `presignableRequest` type to ensure type safety and clarity when passing this parameter. - Modified the S3 client (`S3.ts`) to include `contentType` when making presign requests. - Updated the example HTML (`rewrite-test.html`) to send `contentType` in presign requests and enabled multipart uploads for testing. [[1]](diffhunk://#diff-ca9bc28a71d2d8ac4e0aa6844698f2244594a12e695fc3e153db36674ccb2b52L103-R103) [[2]](diffhunk://#diff-ca9bc28a71d2d8ac4e0aa6844698f2244594a12e695fc3e153db36674ccb2b52R114) --- examples/aws-nodejs/index.js | 4 +++- examples/aws-nodejs/public/rewrite-test.html | 3 +-- packages/@uppy/aws-s3/src/s3-client/S3.ts | 1 + packages/@uppy/aws-s3/src/s3-client/types.ts | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/aws-nodejs/index.js b/examples/aws-nodejs/index.js index febb4f810..ae496293b 100644 --- a/examples/aws-nodejs/index.js +++ b/examples/aws-nodejs/index.js @@ -357,7 +357,7 @@ app.delete('/s3/multipart/:uploadId', (req, res, next) => { app.post('/s3/presign', async (req, res, next) => { try { - const { method, key, uploadId, partNumber } = req.body + const { method, key, uploadId, partNumber, contentType } = req.body const client = getS3Client() if (!method || !key) { @@ -381,12 +381,14 @@ app.post('/s3/presign', async (req, res, next) => { command = new PutObjectCommand({ Bucket: bucket, Key: key, + ContentType: contentType || 'application/octet-stream', }) } else if (method === 'POST' && !uploadId) { // CreateMultipartUpload command = new CreateMultipartUploadCommand({ Bucket: bucket, Key: key, + ContentType: contentType || 'application/octet-stream', }) } else if (method === 'POST' && uploadId) { // CompleteMultipartUpload diff --git a/examples/aws-nodejs/public/rewrite-test.html b/examples/aws-nodejs/public/rewrite-test.html index 3833fb9e2..350c19370 100644 --- a/examples/aws-nodejs/public/rewrite-test.html +++ b/examples/aws-nodejs/public/rewrite-test.html @@ -65,7 +65,6 @@ id: 'AwsS3-STS', bucket: window.UPPY_S3_BUCKET, // Set by server region: window.UPPY_S3_REGION || 'us-east-1', - // Get temporary credentials from /s3/sts getCredentials: async ({ signal }) => { const response = await fetch('/s3/sts', { signal }) @@ -100,7 +99,6 @@ id: 'AwsS3-Sign', bucket: window.UPPY_S3_BUCKET, region: window.UPPY_S3_REGION || 'us-east-1', - // Sign requests via /s3/presign endpoint (returns presigned URLs) signRequest: async (request) => { const response = await fetch('/s3/presign', { @@ -111,6 +109,7 @@ key: request.key, uploadId: request.uploadId, partNumber: request.partNumber, + contentType: request.contentType, }), }) if (!response.ok) throw new Error('Failed to get presigned URL') diff --git a/packages/@uppy/aws-s3/src/s3-client/S3.ts b/packages/@uppy/aws-s3/src/s3-client/S3.ts index d26e3df2f..676cf02b7 100644 --- a/packages/@uppy/aws-s3/src/s3-client/S3.ts +++ b/packages/@uppy/aws-s3/src/s3-client/S3.ts @@ -236,6 +236,7 @@ class S3mini { key, uploadId, partNumber, + contentType, }) // Build request headers diff --git a/packages/@uppy/aws-s3/src/s3-client/types.ts b/packages/@uppy/aws-s3/src/s3-client/types.ts index 8a2b51251..227efd3ab 100644 --- a/packages/@uppy/aws-s3/src/s3-client/types.ts +++ b/packages/@uppy/aws-s3/src/s3-client/types.ts @@ -5,6 +5,7 @@ export type presignableRequest = { uploadId?: string partNumber?: number expiresIn?: number + contentType?: string } /** Response with the pre-signed URL */