Skip to content

fix(storage): forward duplex option for stream uploads via uploadToSignedUrl - #2287

Merged
mandarini merged 1 commit into
developfrom
fix/storage-upload-to-signed-url-duplex
Apr 27, 2026
Merged

mandarini merged 1 commit into
developfrom
fix/storage-upload-to-signed-url-duplex

Conversation

@mandarini

@mandarini mandarini commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

Closes the residual stream-handling parity gap in uploadToSignedUrl left over from #2275. Without this, uploading a ReadableStream or Node Readable through a signed URL fails on Node 20+ with RequestInit: duplex option is required when sending a body.

What changed?

  • packages/core/storage-js/src/packages/StorageFileApi.ts: in the raw-body branch of uploadToSignedUrl, mirror the stream detection block from uploadOrUpdate (StorageFileApi.ts:122-130). When the body is a ReadableStream or a Node Readable (duck-typed via .pipe), set options.duplex = 'half' if the caller did not already supply it. Forward duplex through the put call so it reaches fetch.
  • packages/core/storage-js/test/storageFileApi.test.ts: two mock-based tests proving (a) auto-detection sets duplex: 'half' for stream-shaped bodies, and (b) a caller-provided duplex is forwarded.
  • packages/core/storage-js/test/storageFileApiNode.test.ts: real-infrastructure test that creates a signed URL and uploads fs.createReadStream through it, with no explicit duplex, against the Supabase storage Docker server.

No new helpers were needed: FileOptions.duplex (src/lib/types.ts:160-162) and FetchOptions.duplex (src/lib/common/fetch.ts:11-17) already exist, and the put helper already forwards duplex to fetch via _getRequestParams (src/lib/common/fetch.ts:114-116).

Why was this change needed?

uploadOrUpdate honors stream bodies; uploadToSignedUrl did not. PR #2275 brought parity for metadata, fileOptions.headers, and cacheControl de-dup on caller FormData, but the stream/duplex case stayed broken. Verified server-side that this is safe: PUT /object/upload/sign/:bucket/* and POST /object/:bucket/* route through the same fileUploadFromRequest -> Uploader.upload() pipeline (uploader.ts:421-568), so raw stream bodies parse identically on both endpoints.

Closes #2274 (residual gap), helps close supabase/storage#823.

Screenshots/Examples

Before this change on Node 20+:

import fs from 'fs'

const { data: { token } } = await supabase.storage
  .from('bucket')
  .createSignedUploadUrl('path/file.txt')

await supabase.storage
  .from('bucket')
  .uploadToSignedUrl('path/file.txt', token, fs.createReadStream('file.txt'))
// throws: RequestInit: duplex option is required when sending a body

After: succeeds and the file lands in storage. Callers can also pass { duplex: 'half' } explicitly to override.

Breaking changes

  • This PR contains no breaking changes

The change is additive: the only new behavior is auto-setting duplex: 'half' when the body is detected as a stream. Existing callers (Blob, FormData, raw string/Buffer/Uint8Array) are unaffected.

Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run npx nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

Additional notes

Test results locally:

  • nx build storage-js: ok
  • nx test storage-js (mock unit tests): 12/12 uploadToSignedUrl tests pass, including the 2 new ones
  • nx test:storage storage-js (full Docker suite, includes the new Node integration test): 388 passed, 2 skipped

@mandarini
mandarini requested review from a team as code owners April 27, 2026 14:23
@github-actions github-actions Bot added the storage-js Related to the storage-js library. label Apr 27, 2026
@mandarini mandarini self-assigned this Apr 27, 2026
@pkg-pr-new

pkg-pr-new Bot commented Apr 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2287

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2287

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2287

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2287

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2287

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2287

commit: 4cdd841

@mandarini
mandarini merged commit 7479009 into develop Apr 27, 2026
25 checks passed
@mandarini
mandarini deleted the fix/storage-upload-to-signed-url-duplex branch April 27, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage-js Related to the storage-js library.

Projects

None yet

3 participants