Repository navigation
feat(upload): upload straight to the final storage path with a signed token - #360
Merged
Merged
Conversation
… token Ask the API for a signed upload token when getting an upload URL. When one comes back, upload the Supabase copy with TUS straight to the final path through /storage/v1/upload/resumable/sign, sending the token as x-signature, so the API has nothing to copy when it finalises. The token is refreshed before a request when it is close to expiry, and when Storage refuses it, so a long upload carries on. If the signed upload fails, or the API offers none, the CLI uploads to the temp path as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Today the CLI uploads the Supabase copy of a binary or flow zip to a temporary path. When the upload is finalised, the API copies it to its final path. For a large binary, that copy is slow.
With this change, the CLI asks for a signed upload token when it requests an upload URL. If the API returns one, the CLI uploads straight to the final path, so there's nothing to copy.
How it works
getBinaryUploadUrlandgetFlowUploadUrlnow sendsignedUpload: true.signedUpload: { path, token, expiresInSeconds }./storage/v1/upload/resumable/sign, with the token in thex-signatureheader.x-upsertis no longer sent on this path.useTus: true, so the API checks the file is there and skips its copy.submitFlowTestalready sendsuseTus: true; it now gets the final path too.Token expiry
Storage checks the token on every TUS request, and a token lasts about two hours. So:
POST /uploads/refreshUploadTokenif the current one has less than 10 minutes left.Fallback
The Backblaze upload is unchanged.
Tests
New
test/unit/signed-upload.test.ts:x-upsertuploadSupabaseCopy:pnpm lint,pnpm typecheck,pnpm test:unit(779 passing) andpnpm buildall pass.Not yet tested against real Storage. That needs the matching API change deployed to dev. Before releasing, check on dev:
🤖 Generated with Claude Code