Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@aws-sdk/lib-storage": "3.654.0",
"@aws-sdk/s3-request-presigner": "3.654.0",
"@fastify/accepts": "^4.3.0",
"@fastify/multipart": "^8.3.1",
"@fastify/multipart": "github:supabase/fastify-multipart#v8.3.1-patched",
"@fastify/rate-limit": "^7.6.0",
"@fastify/swagger": "^8.3.1",
"@fastify/swagger-ui": "^4.1.0",
Expand Down
11 changes: 9 additions & 2 deletions src/storage/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export async function fileUploadFromRequest(

try {
userMetadata = JSON.parse(customMd)
} catch (e) {
} catch {
// no-op
}
}
Expand Down Expand Up @@ -381,6 +381,13 @@ export async function fileUploadFromRequest(
}
}

// Detect if the request stream closed before we could pass it to the storage backend
// Without this check, the storage backend (S3) would throw a 500 "Premature close" error
// when attempting to read from the closed stream. We catch this early and return 400.
if (!body || body.closed || body.destroyed || body.readableEnded) {
throw ERRORS.NoContentProvided(new Error('Request stream closed before upload could begin'))
}

return {
body,
mimeType,
Expand All @@ -395,7 +402,7 @@ export function parseUserMetadata(metadata: string) {
try {
const json = Buffer.from(metadata, 'base64').toString('utf8')
return JSON.parse(json) as Record<string, string>
} catch (e) {
} catch {
// no-op
return undefined
}
Expand Down
Loading