mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
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)
This commit is contained in:
parent
828b8df284
commit
3529f97899
4 changed files with 6 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue