Skip to content

fix: complete empty TUS multipart uploads when Upload-Length is 0 - #1365

Closed
hsusul wants to merge 1 commit into
supabase:masterfrom
hsusul:fix/tus-zero-byte-upload-length
Closed

fix: complete empty TUS multipart uploads when Upload-Length is 0#1365
hsusul wants to merge 1 commit into
supabase:masterfrom
hsusul:fix/tus-zero-byte-upload-length

Conversation

@hsusul

@hsusul hsusul commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Resumable (tus) upload creation with Upload-Length: 0 returns 404 with no explanation #1300: resumable upload creation with Upload-Length: 0 returned a bare 404 because TUS treats size-0 as immediately final (no write()), while @tus/s3-store create() only starts a multipart upload. Our onUploadFinish then HeadObjects a key that does not exist yet.
  • Override S3Store.create to call upstream finishMultipartUpload(metadata, []) (which already uploads a zero-byte part when parts is empty), then complete metadata and clear cache, so the object exists before finish runs.
  • Unit tests cover size 0 finalization and that non-zero / deferred sizes are unchanged.

Test plan

  • npm run test:unit -- src/storage/protocols/tus/s3-store.test.ts
  • Manual: POST /storage/v1/upload/resumable with Upload-Length: 0 and valid Upload-Metadata201, object exists as empty
  • Manual: same with Upload-Length: 1 + PATCH still succeeds

TUS marks size-0 uploads final without write(), so S3Store.create must
finish the empty multipart before onUploadFinish HeadObject runs.
@hsusul
hsusul requested a review from a team as a code owner September 4, 2026 15:47
@ferhatelmas

ferhatelmas commented Sep 4, 2026

Copy link
Copy Markdown
Member

Thanks, we need to fix it in upstream, not here. Could you direct your patch there? I can give look for review

@hsusul

hsusul commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — agreed this belongs upstream.

Opened the fix in tus-node-server: tus/tus-node-server#876

Closing this PR in favor of that.

@hsusul hsusul closed this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resumable (tus) upload creation with Upload-Length: 0 returns 404 with no explanation

2 participants