Repository navigation
refactor(assets)!: move direct uploads to presigned PUT for uppy v6 - #202
Merged
Merged
Conversation
@uppy/aws-s3 v6 is a rewrite, not a bump. `getUploadParameters`, `endpoint`,
`headers` and the whole multipart callback surface are gone, replaced by three
mutually exclusive signing modes. The S3 POST policy our upload flow was built
on has no equivalent there, so the whole path moves to a presigned PUT.
- /presign signs a PUT and returns `{ method, url }`. It signs neither
:content_type nor :content_disposition — both would become SigV4 signed
headers the browser must reproduce exactly, and v6 sends only Content-Type,
so signing either turns a mismatch into SignatureDoesNotMatch. Nothing is
lost: cache objects are never served, and Shrine's S3 storage sets the
content type and an inline disposition when it promotes the file to `store`,
which is the copy users actually download.
- The server still mints the object key. v6 generates one client-side and hands
it to `signRequest`; we ignore it and sign our own, so a caller cannot aim an
upload at another user's pending cache entry or at `store/`.
- The dev/test stand-in for S3 becomes a raw PUT carrying the key in its path,
because the plugin derives a file's uploadURL from the presigned URL minus its
query string and the frontend parses the cache id back out of it. That URL has
to be absolute — v6 feeds it to `new URL()` with no base.
- Middleware::RawUploadBody (dev/test) stops ActionDispatch from parsing a
`.json` asset's body as request params, which would 400 every such file that
is not itself valid JSON before the action could store it.
- Drops Shrine's presign_endpoint/upload_endpoint config. presign_endpoint was
already dead: nothing mounted its Rack app and nothing called presign_response
— the controller always signed :cache by hand — and its lambdas encoded the
POST-policy contract that no longer exists. upload_endpoint was live, but only
through the `upload_response` call in the action rewritten here; it parses a
multipart form, which a raw PUT is not, so it goes with it.
The POST policy's :content_length_range has no presigned-PUT equivalent, so the
1 GB cap is no longer asserted at presign time. The enforcing check is
unchanged: AssetFileUploader's validate_max_size runs on promotion against the
bytes actually stored, so an oversized upload can reach cache storage but can
never become an asset.
Vitest stubs Uppy inert (docs/testing.md R8), so the plugin's signing protocol
has no coverage there — a system test now drives the real chain in a headless
browser, including the .json case, and the request tests pin the production S3
branch (key reachable in the URL path, `host` the only signed header).
BREAKING CHANGE: POST /api/v1/assets/upload becomes
PUT /api/v1/assets/upload/*key, and /api/v1/assets/presign no longer returns
`fields` or `headers`. Both are internal to the browser upload flow.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
This was referenced Sep 5, 2026
This was referenced Sep 5, 2026
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.
@uppy/aws-s3v6 is a rewrite, not a bump, so this replaces #189 and #190 rather than merging them.getUploadParameters— which our whole upload flow was built on — is gone, along withendpoint,headers,signPartand the rest of the multipart callback surface. Signing collapses to three mutually exclusive modes (signRequest,getCredentials,companionEndpoint), and none of them has an S3 POST-policy equivalent. Our#presignreturned a POST policy in production and a hand-built stand-in for it locally, so the whole path had to move to a presigned PUT, frontend and backend together.What changed
/presignsigns a PUT and returns{ method, url }. It signs neither:content_typenor:content_disposition. Both would become SigV4 signed headers the browser must reproduce byte-for-byte, and v6 sends onlyContent-Type— so signing either turns any mismatch intoSignatureDoesNotMatch. Nothing is lost: cache objects are never served (the frontend hands the id straight back to us), andShrine::Storage::S3#uploadsets the content type from the marcel-derived mime type and an inlinecontent_dispositionwhen it promotes the file tostore, which is the copy users actually download.The server still mints the object key. v6 generates a key client-side and passes it to
signRequest; we ignore it and sign our own. Otherwise a caller could aim an upload at another user's pending cache entry or atstore/.generateObjectKeyis repurposed to carry the Uppy file id across tosignRequest, which is handed nothing but{ method, key }.The dev/test stand-in for S3 becomes a raw PUT with the key in its path (
PUT /api/v1/assets/upload/*key), because the plugin derives a file'suploadURLfrom the presigned URL minus its query string, and the frontend parses the cache id back out of that path. That URL has to be absolute — v6 feeds it tonew URL()with no base.Middleware::RawUploadBody(dev/test) stops ActionDispatch from parsing a.jsonasset's body as request params, which would400every such file that isn't itself valid JSON before the action could store it. Parsing is triggered by ActionController's own instrumentation ahead of every callback, so there is no hook inside the controller that can opt out.Drops Shrine's
presign_endpoint/upload_endpointconfig.presign_endpointwas already dead: nothing mounted its Rack app and nothing calledpresign_response— the controller always signed:cacheby hand — and its lambdas encoded the POST-policy contract that no longer exists (two of them would now raise, since the glob route requires akey).upload_endpointwas live, but only through theupload_responsecall in the action rewritten here; it parses a multipart form, which a raw PUT is not.Local behaviour is otherwise unchanged: uploads still land in the same
:cachestorage, i.e.public/cache/…in development.One accepted regression
The POST policy's
:content_length_rangehas no presigned-PUT equivalent, so the 1 GB cap is no longer asserted at presign time. The enforcing check is unchanged:AssetFileUploader'svalidate_max_sizeruns on promotion against the bytes actually stored, so an oversized upload can reach cache storage but can never become an asset. Presign also still requires an authenticated, non-read-only user.It can be restored by signing
Content-Length(whitelist_headers: ["content-length"]— the AWS SDK leaves it unsigned by default), but that trades a real production-breakage risk for a bound an authenticated user can already work around by presigning repeatedly. Happy to add it if you'd rather have it.Testing
Vitest stubs
@uppy/coreand@uppy/aws-s3inert (docs/testing.md R8), so the plugin's signing protocol has no coverage there — the layer that a major version bump breaks is exactly the one the unit suite cannot see. So:test/system/asset_upload_test.rb) drives the real chain in headless Chromium: real Uppy v6 signs, PUTs, and the frontend parses the resultinguploadURLand promotes it to a company asset. Includes the.jsoncase thatRawUploadBodyexists for. This is what caught thenew URL()bug — a path-relative presign URL threwInvalid URLand the upload silently never started.test/integration/api/v1/assets_upload_test.rb) cover all three storages: Memory (test), a realShrine::Storage::FileSystemin a tmpdir (development — a genuinely different write path,IO.copy_streamvsio.read), and a realShrine::Storage::S3for the production branch, pinning that the key is reachable in the URL path and thathostis the only signed header.ActionController::TestCasefor these actions is replaced: the upload path only behaves correctly with the full middleware stack, which a controller test runs without.make check_allgreen: brakeman, eslint, fe-test, fsd, rails-test, rubocop, system-test, typescript, vite-build. Backend coverage 92.18%, frontend 80.76%.Breaking
POST /api/v1/assets/uploadbecomesPUT /api/v1/assets/upload/*key, and/api/v1/assets/presignno longer returnsfieldsorheaders. Both are internal to the browser upload flow — no external consumer.Supersedes #189 and #190.
🤖 Generated with Claude Code