Skip to content

Admin panel

File upload fields

A file field is a col.storage() column. The column holds text, the object’s key in the bucket (or its URL, if the column says so), and the CMS draws it as an upload field with a preview.

What a storage field does is split in two, by where it runs:

Declared Where Options
on the column, in backend/schema read by the server and the CMS path, source, accept, maxBytes, imageResize, public, fileName, metadata, includeBucketUrl, storeUrl
in customizeTable, in frontend/src/cms the browser only storage.path(…), storage.fileName(…), storage.processFile, storage.postProcess, storage.previewUrl

The column’s options are serializable, so they travel in the table’s descriptor and the server enforces what it can of them. The customizeTable options are functions: they cannot reach the server, so they shape only uploads made from the CMS.

// backend/schema/listings.ts
import { defineTable, col } from "@rebasepro/server/schema";
export const listings = defineTable("listings", {
columns: {
id: col.uuid().primaryKey().defaultRandom(),
title: col.text().notNull(),
cover: col.storage({ path: "listings/{id}/", accept: ["image/*"], maxBytes: "10MB",
imageResize: { maxWidth: 1600, format: "webp", quality: 80 } }),
photos: col.storage({ path: "listings/{id}/gallery/", accept: ["image/*"] }).multiple(),
},
rls: "admin-only",
});

cover is an upload field that takes one image of at most 10 MB, resized to at most 1600 pixels wide and stored as WebP. A column whose accept names an image type previews as an image, and the first such column fills the record’s image slot in cards and lists.

.multiple() makes the column a TEXT[] and the field a multi-file upload, reorderable by dragging. Every option applies to each file.

// frontend/src/cms/listings.tsx
import { customizeTable } from "@rebasepro/cms";
import type { listings } from "../../../backend/schema/listings";
export const listingsCms = customizeTable<typeof listings>("listings", {
fields: {
cover: {
storage: {
// A folder per listing title, computed in the browser.
path: ({ values }) => `listings/${String(values.title ?? "untitled").toLowerCase()}/`,
fileName: ({ file }) => `${Date.now()}-${file.name}`,
},
urlPreview: "image",
},
photos: {
sortable: true,
storage: { processFile: async (file) => file },
},
},
});
storage. Runs Effect
path(context) before an upload The folder the file goes to, replacing the column’s path template.
fileName(context) before an upload The stored file name, replacing the column’s fileName template. May be async.
processFile(file) before an upload Transforms the file (compress, strip metadata).
postProcess(pathOrUrl) after an upload Transforms the path or URL before it is written to the column.
previewUrl(fileName) when drawing The URL to preview a stored file at, when it is not the field’s value.

path and fileName are handed the upload’s context: the file, the record’s id (absent on a new record), its values as edited, the propertyKey and the resolved storage rules. On a .multiple() column, the same storage options go directly on the field and apply to each file.

urlPreview sets how the stored value is previewed ("image", "video", "audio", "file", or true for a link), and clearable adds a control that empties the field.

accept and maxBytes are enforced by the server against where the file lands. A column’s path is where its files go, so it is also where its limits hold: every upload whose key is a file directly under that path meets them, from the CMS, client.storage.putObject, a resumable upload, the Studio’s storage browser or curl, whether or not it names the column, on the column’s own bucket. Placeholders match whatever the CMS would fill in: {id}, {rand}, {file} and the like stand for one path segment, {path} for any number. A public: true column’s path is under public/.

  • Several columns sharing one path: a file one of them accepts is accepted.
  • An upload that also names its column, as the CMS’s uploads do, is held to that column too. Naming a looser column does not unlock a stricter one’s path.
  • A storage.path function in customizeTable cannot be read by the server, so a file uploaded under the path it computes is held to the column’s limits only when the upload names the column, which the CMS’s uploads always do.
  • A path no column claims is held to the bucket’s own limit (STORAGE_MAX_FILE_SIZE) alone.

imageResize, processFile and postProcess happen in the browser, before the bytes are sent: a file uploaded another way is stored as it was sent.

path is a default, not a boundary: nothing on the server confines an upload to it. Who may write where is a storage authorization rule; see Storage.

Clearing a file field, replacing its file, or deleting the row leaves the stored object where it is. Every upload gets a key of its own, so a replacement writes a new object, and nothing removes the previous one: two rows can hold the same key, so the CMS cannot know a file is unused. Objects no row points at stay in the bucket, and are billed, until you delete them from the Studio’s storage browser, with client.storage.deleteObject(key), or with a lifecycle rule on the bucket. rebase storage orphans lists the files no row names, and deletes them with --delete; see the CLI.

A file field stores the object’s key, not its bucket. Changing a column’s source points every existing value at the new bucket, where those keys do not exist, so previews of older files answer “not found”. Copy the objects to the new bucket under the same keys first, with rebase storage move --from <old> --to <new> --prefix <path> or the provider’s own tooling, such as aws s3 sync or gcloud storage cp, or keep the old bucket for the existing files.

  • Columns: every col.storage() option
  • Fields: the other column types
  • Storage: buckets, signed URLs, and what the server does with an upload
  • Files in the SDK: storage references inside text