TotalBase
Files

Using Files in Tables

Photo, file and signature columns, and reading files through the API.

In the admin: Database › Add column › Photo, File, Signature

A column that holds a file is a uuid with a foreign key to the files table. Add column › Photo, File or Signature creates it:

ALTER TABLE public.work_orders
  ADD COLUMN customer_signature uuid REFERENCES totalbase.files (id);

Forms show such a column as a file upload, a camera or a signature pad; grids and cards show the image as a thumbnail. A foreign key to the files table you add in SQL works the same way.

Several files per row, such as a work order's photos, go in a child table:

CREATE TABLE public.work_order_photos (
  id         uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  work_order uuid NOT NULL REFERENCES public.work_orders (id) ON DELETE CASCADE,
  file       uuid NOT NULL REFERENCES totalbase.files (id),
  caption    text,
  taken_at   timestamptz NOT NULL DEFAULT now()
);

A DataView over work_orders shows them as a panel in the order's form. See Widgets.

Granting READ on a table that references files doesn't grant READ on the files. A role that sees work orders also needs READ on files to open their photos. See Who can see a file.

The files API

Route
POST /api/totalbase/table/filesupload (multipart). See Uploading
GET /api/totalbase/table/files/{id}the content, with its type; images take transformations
GET /api/totalbase/table/files/{id}/infothe details
PATCH /api/totalbase/table/files/{id}change visibility, description, tags, name or folder
PUT /api/totalbase/table/files/{id}/contentreplace the content (multipart file, or JSON text)
DELETE /api/totalbase/table/files/{id}delete the file and its content (204)
GET /api/totalbase/table/fileslist and search files, through the Data API
/api/totalbase/table/foldersfolders, through the Data API

A public file's content is served without credentials; everything else takes the caller's token or session.

Next steps