Skip to content

refactor(assets)!: move direct uploads to presigned PUT for uppy v6 - #202

Merged
artempartos merged 1 commit into
developfrom
chore/uppy-6-migration
Sep 5, 2026
Merged

artempartos merged 1 commit into
developfrom
chore/uppy-6-migration

Conversation

@artempartos

Copy link
Copy Markdown
Contributor

@uppy/aws-s3 v6 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 with endpoint, headers, signPart and 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 #presign returned 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

/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 byte-for-byte, and v6 sends only Content-Type — so signing either turns any mismatch into SignatureDoesNotMatch. Nothing is lost: cache objects are never served (the frontend hands the id straight back to us), and Shrine::Storage::S3#upload sets the content type from the marcel-derived mime type and an inline content_disposition when it promotes the file to store, 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 at store/. generateObjectKey is repurposed to carry the Uppy file id across to signRequest, 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's uploadURL from 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 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 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_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 (two of them would now raise, since the glob route requires a key). 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.

Local behaviour is otherwise unchanged: uploads still land in the same :cache storage, i.e. public/cache/… in development.

One accepted regression

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. 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/core and @uppy/aws-s3 inert (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:

  • New system test (test/system/asset_upload_test.rb) drives the real chain in headless Chromium: real Uppy v6 signs, PUTs, and the frontend parses the resulting uploadURL and promotes it to a company asset. Includes the .json case that RawUploadBody exists for. This is what caught the new URL() bug — a path-relative presign URL threw Invalid URL and the upload silently never started.
  • New request tests (test/integration/api/v1/assets_upload_test.rb) cover all three storages: Memory (test), a real Shrine::Storage::FileSystem in a tmpdir (development — a genuinely different write path, IO.copy_stream vs io.read), and a real Shrine::Storage::S3 for the production branch, pinning that the key is reachable in the URL path and that host is the only signed header.
  • The grandfathered ActionController::TestCase for these actions is replaced: the upload path only behaves correctly with the full middleware stack, which a controller test runs without.

make check_all green: 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/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 — no external consumer.

Supersedes #189 and #190.

🤖 Generated with Claude Code

@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]>
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.

1 participant