Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Uploads and File Ownership
Status: In Progress — 6.0 scope being built on feat/uploads-api (upload contract, parameter rename, store ownership, orphan purge)
Target: Spree 6.0 (upload contract, multipart uploads, store ownership) · Spree 6.1 (enforcement, uploader)
Depends on: 6.0-media-library.md (media rows, blob reuse), 6.0-mcp-server.md (MCP upload_file and export tools reach files through the Admin API), 6.0-digital-assets.md (private uploads)
Author: Damian + Claude
Last updated: 2026-10-10
Tracking: Linear V-3742 · GitHub spree/spree#14865
Summary
Files reach Spree through POST /api/v3/admin/direct_uploads, a presigning helper whose request and response follow Active Storage's own shape: nested parameters, a private flag, and a signed blob ID that never expires as the only reference. Two problems follow from that.
- Blobs have no owner. Nothing records which store uploaded a file, so a
signed_idfrom one store can be attached in another, and storage cannot be measured or cleaned up per store. - The contract describes the storage library, not the API. It breaks the flat-params rule for v3, a leaked reference stays attachable forever, and a caller that cannot run a presigned upload, such as the MCP server or the CLI, has no way to send a file at all.
6.0 replaces the endpoint with POST /api/v3/admin/files: a flat request, an expiring opaque reference, and a second way to upload where the bytes travel in the request itself. It also records which store owns every blob. The Admin and Seller APIs are not yet stable, so the old endpoint is removed in the same release, without an alias. 6.1 only tightens: attaching a file from another store is refused, and uploads record who made them. No model changes, so 6.x stays stable for everything built on attachments.
Key Decisions (do not deviate without discussion)
6.0
POST /api/v3/admin/filesreplaces/direct_uploads, with no alias. The Admin and Seller APIs are not yet stable, so the old endpoint and its request shape are removed in the same release, not deprecated. "Direct" stops being true once the endpoint also accepts the bytes themselves./filesnames what the caller sends, in the API's own words rather than the storage library's; onlycreateexists in 6.0, so it promises no listing or fetching yet (decided 2026-10-10 over/uploads). The Seller API gets the same endpoint.- Flat request.
filename,content_type,byte_size,checksum(base64 MD5) andvisibility(publicorprivate) sit at the top level, following the flat-params rule for v3. The{ blob: { … } }wrapper and theprivate: trueflag are gone. - Two ways to upload, one response.
- Presigned: JSON metadata returns a target the client PUTs the bytes to. The dashboard and seller panel use this, so large files go straight to storage.
- Multipart: a
filepart in the request, and the server stores the bytes itself, returning the same response withupload: null. The MCP server and the CLI use this. A caller that cannot make a second request (a model calling a tool) needs it, and on disk storage it avoids a presigned target that points back at the same application.
signed_idkeeps its name and is documented as opaque. Every write endpoint already accepts it. Clients pass it back unchanged and must not parse it, so the way references are issued can change without breaking anyone.- Signed IDs expire. Uploads mint
signed_id(expires_in: 1.day), returned withexpires_at. Responses that offer an existing file for reuse (the media library) mint a fresh one on each read. A leaked reference is no longer attachable forever. - Blobs belong to a store. A nullable
store_idcolumn onactive_storage_blobs; Active Storage ignores columns it does not define. Set when every blob is created, and backfilled for existing rows by the 6.0 upgrade. - 6.0 checks and logs; 6.1 refuses. Attaching a blob whose store differs from its owner's, or that has no store, is logged in 6.0 and refused from 6.1. One release of logs finds every path that creates blobs without a store before anything depends on the check.
- Image URLs are documented as opaque. Clients store and render them as given and never build or parse them, so the format and host can change (a CDN, a different storage service) without breaking anyone.
- Every upload reference parameter is named
signed_idor<slot>_signed_id(2026-10-10). Renamed in the same change as the endpoint, while the breaking window is open:avatar→avatar_signed_id,logo→logo_signed_id,image→image_signed_id,document→document_signed_id,attachment→attachment_signed_id,file→file_signed_id,po_document→po_document_signed_id, and so on for every slot. Clients no longer translate between names; the old names are removed, not aliased, in the Admin and Seller APIs, and the Store API change is in the upgrade guide. - Public uploads are allowlisted, private uploads are open (2026-10-10). Public: web image types,
Spree::Config.video_content_typesandtext/csv. Private: any type, because digital products are ebooks, archives and audio, and the attachment's own validation is the real check. Limits are installation settings:Spree::Config.max_upload_size(5 GB) for presigned uploads andmax_multipart_upload_size(10 MB, matching MCPupload_file) for multipart. - Never-attached uploads are purged by a daily core job (2026-10-10). Rails purges nothing on its own and neither did Spree.
Spree::Uploads::PurgeUnattachedJobremoves blobs that belong to a store and have no attachment, older thanSpree::Config.unattached_upload_retention_days(default 2, longer than the 1-day reference expiry, so nothing a client can still attach is lost). An installation setting rather than a store one: storage is installation infrastructure. - The Store API purchase-order presigner adopts the same contract and stays nested (2026-10-10).
POST /api/v3/store/carts/:cart_id/po_documentkeeps its cart-scoped route, because a publishable key is public and must not mint uploads freely, but takes the flat request, returns the same response shape with an expiringsigned_id, and records the store. It is the one exception to "uploads go through/filesonly". - MCP is not on
mainyet (2026-10-10). The MCP server branch (6.0-mcp-server.md) adopts the multipart request when it rebases; this change ships the endpoint it will call.
6.1
- The store check refuses. After a release of 6.0 logs, attaching a blob from another store, or one with no store, is refused.
- Uploads record who made them (2026-10-10).
uploaded_by_type/uploaded_by_idonactive_storage_blobs, short type names per6.0-action-actors.md, set by the same creation hook that setsstore_id. One migration and one hook line answer "who uploaded this file" for audits and seller disputes.
Design Details
The upload contract
Presigned:
POST /api/v3/admin/files
Content-Type: application/json
{ "filename": "products.csv", "content_type": "text/csv", "byte_size": 48213,
"checksum": "<base64 MD5>", "visibility": "private" }
201
{ "signed_id": "…opaque…",
"filename": "products.csv", "content_type": "text/csv", "byte_size": 48213,
"visibility": "private", "expires_at": "2026-10-11T12:00:00Z",
"upload": { "method": "PUT", "url": "https://…", "headers": { "Content-MD5": "…" } } }
The client PUTs the bytes to upload.url with upload.headers, treating both as opaque, then passes signed_id to the endpoint that uses the file.
Multipart:
POST /api/v3/admin/files
Content-Type: multipart/form-data
filename, content_type, visibility, file=<bytes>
The server takes byte_size and checksum from the bytes it received and returns the same response with upload: null. The file is already stored.
Both ways:
- The endpoint enforces the content-type allowlist for public uploads and the size limit for both. Multipart has a lower limit, because the bytes pass through the application; larger files use the presigned upload.
visibilityselects the public or private storage service.store_idis set on the blob (see below).- The Seller API's
POST /api/v3/seller/filesis identical, behind the seller's own scope.
Callers that move in the same change. The admin and seller SDKs replace directUploads.create() with files.create(), plus a helper that runs create and PUT and returns the signed_id in one call. These move together:
- Dashboard and seller panel: product and variant media and posters, digital assets, imports, shipping labels, the store logo and mailer logo, avatars, tax exemption certificates, and seller requirement submissions.
- MCP:
upload_filedispatches the multipart request through the Admin API, replacing its direct blob creation. - CLI:
spree apigains an upload command built on the multipart request.
Store ownership
- Column:
active_storage_blobs.store_id, nullable, indexed. - Set on creation:
POST /filespassesstore_id: current_store.idin both ways of uploading.- Blobs Spree creates internally (imports, exports, shipping labels, data requests, seeds) get the store from one
ActiveSupport.on_load(:active_storage_blob)hook readingSpree::Current.store.
- Checked on attachment: one check when an
ActiveStorage::Attachmentis created. The blob's store must equal the owning record's store:record.store_id, or the owner's store for records without one (media through its viewable, variants through their product). It lives on the attachment model, so controllers, workflows, extensions and console use are all covered.- In 6.0 a mismatch, or a blob with no store, is logged with the attachment slot and owner. From 6.1 it is refused.
- Records with no store (global admin avatars) are exempt.
- Backfill:
spree:uploads:assign_storesruns as part of the 6.0 upgrade manifest (afterdb:migrate), as anActiveJob::Continuabletask with one set-basedUPDATE … FROM active_storage_attachments JOIN <owner table>per attachment slot, in ID ranges, safe to rerun. A blob attached in two stores is reported, not resolved. Unattached blobs are left without a store, and the daily purge leaves them alone: it only deletes files that belong to a store, since a host app may keep blobs of its own outside attachments (2026-10-10, from review).
What ownership enables beyond the security check:
- storage used per store;
- cleanup of a store's orphaned uploads;
- deleting a store's files when the store is deleted.
Migration Path
6.0
- Migration (
[8.1]):store_id, indexed, onactive_storage_blobs. POST /filesfor the Admin and Seller APIs: the flat request,visibility, presigned and multipart uploads, the response shape, expiringsigned_id, andstore_idon the blob./direct_uploadsand its controllers, concern and routes are deleted.- The store hook on internal blob creation, and the store check on attachment creation, logging only.
- Admin and seller SDK
files.create()plus the helper;directUploadsremoved. The dashboard and seller panel move every upload flow over. MCPupload_filedispatches the multipart request.spree apigains the upload command. Regenerate types, Zod schemas and OpenAPI. spree:uploads:assign_storesin the 6.0 upgrade manifest, with a report of blobs attached in two stores.- Every upload reference parameter renamed to
signed_id/<slot>_signed_id, and the daily purge of never-attached uploads. - Docs: an uploads page (both ways of uploading, the opaque
signed_id, expiry, visibility, size limits), image URLs andsigned_idcalled out as opaque in the API introduction, and a changelog entry for the endpoint replacement.
6.1
- The store check refuses mismatches and blobs with no store.
- Uploader columns (
uploaded_by_type,uploaded_by_id).
Constraints on Current Work
- Uploads go through
POST /filesonly. Do not add another way to create a blob from the API. - Never put a blob ID, storage key or Rails blob URL in an API response. Public images go through
image_url_for/cdn_image_url. Upload references aresigned_idvalues, minted with an expiry. - Every blob Spree creates belongs to a store. Pass
store_id, or create it inside a request or job whereSpree::Current.storeis set. A 6.0 log line about a blob with no store is a bug to fix before 6.1 starts refusing. - No new
has_many_attached. A record with several images uses media rows; a private document is a singlehas_one_attachedslot. - An image a merchant picks or reuses is a media row, not a new attachment on the owner. Logos, covers and swatches added from now on go through the media library.
- Upload references are parameters named
signed_idor<slot>_signed_id. Do not add new names (document,file,attachment) for the same thing. - Do not build URLs with
rails_blob_*orrails_representation_*helpers outsidecdn_image. Keeping one place that builds image URLs is what lets their host and format change without touching serializers.
Open Questions
None.
References
docs/plans/6.0-media-library.md: media rows, blob reuse and deletion safetydocs/plans/6.0-mcp-server.md: MCPupload_fileand export tools reach files only through the Admin APIdocs/plans/6.0-action-actors.md: actor model foruploaded_byspree/api/app/controllers/spree/api/v3/admin/direct_uploads_controller.rb,spree/api/app/controllers/concerns/spree/api/v3/direct_uploads.rb: the endpoint 6.0 replacesspree/core/config/routes.rb(cdn_image): the one place public image URLs are built