Files
Most real apps need people to attach something: a photo of the broken part, a signed PDF, a profile picture. Uploads are built in and kept with the app; a file someone uploaded opens for them, and for whoever can read a row that holds it, or for everyone once you make it public. Server code can print PDFs into the same store, and your own images, fonts, video, audio and PDFs are served as assets.
When to use which
| You need | Use |
|---|---|
| People attach a file to a record | A ctx.image or ctx.file column and upload from the page |
| A document your app makes (an invoice, a ticket) | ctx.pdf(html) in an action, step.pdf in a workflow |
| Your logo, hero image, icons or fonts | The assets tool (served at /assets/<name>), icons/*.svg, fonts from npm |
| A hero clip, a podcast episode, a menu or brochure PDF | An asset too: /assets/hero.mp4, /assets/menu.pdf |
| An uploaded file on a public page | A row guests can read that holds it, or read: ["any"] |
Uploads
-- db/schema/ticket.sql
create table if not exists ticket (
id uuid primary key default gen_random_uuid(),
body text not null,
photo ctx.image, -- the uploaded file's id
created_at timestamptz not null default now()
);// components/PhotoField.tsx: attach a photo to a ticket.
import { useState } from "react";
import { useAppHandle, useTable } from "@appbricx/ui";
export function PhotoField({ ticketId }: { ticketId: string }) {
const app = useAppHandle();
const tickets = useTable("ticket");
const [error, setError] = useState("");
const pick = async (file: File | undefined) => {
if (!file) return;
setError("");
try {
const { url } = await app.upload(file); // "/__appbricx/files/<file id>"
await tickets.update(ticketId, { photo: url.slice(url.lastIndexOf("/") + 1) });
} catch (e) {
setError(e instanceof Error ? e.message : "Upload failed");
}
};
return (
<label className="grid gap-1">
Photo
<input type="file" accept="image/*" onChange={(e) => void pick(e.target.files?.[0])} />
{error ? <span role="alert">{error}</span> : null}
</label>
);
}Show it with <img src={"/__appbricx/files/" + row.photo} />: that address sends anyone allowed to open the file on to it. Server code gets a resized or converted address with ctx.files.url(id, { w, h, fmt }) and lists uploads with ctx.files.uploads().
Who can open a file
- The person who uploaded it.
- Anyone who can read a row that holds it in a
ctx.imageorctx.filecolumn, under that table's policies. - A write may only put a file into such a column when the writer can already open it (else
403 FILE_FORBIDDEN), so knowing a file's id is never enough to read it. - Whoever its permissions name, when it has any.
- Everyone, signed out too, when a row guests may read holds it, or its permissions say
read: ["any"]. Then it is public: served to visitors and crawlers with a 30-day cache, a video in byte ranges, a PDF inline.
Permissions per file
A file's permissions say who besides its uploader may open it (read), change who may open it (update) and delete it (delete). Set them on upload, later from the page, or from server code:
// in a component: only the legal role opens it, and rows that hold it don't grant it
const { id } = await app.upload(file, { permissions: { read: ["role:legal"], by_reference: false } });
await app.setFilePermissions(id, { read: ["users"] }); // any signed-in user
await app.setFilePermissions(id, null); // back to the default
// server/contracts.ts: server code may change any file's, so check the caller first
await ctx.files.setPermissions(id, { read: ["role:legal", "role:finance"] });- Targets:
any(read only: public, and caches may keep it for 30 days),users(signed in),user:<id>,role:<role>,workspace:<id>orworkspace:<id>/<role>, andworkspace(the uploader's current one); at most 20 a list. - Rows that hold the file still grant reading it unless
by_reference: false. - The console's Storage page shows each file's access and edits it; agents use
storage { action: "permissions" }.
PDFs from server code
// server/invoice.ts
export const invoicePdf = defineAction({
input: v.object({ ref: v.string() }),
roles: ["ops"],
handler: async (ctx, input) => ctx.pdf("<h1>Invoice " + input.ref + "</h1><p>Total 14,400</p>", { name: "invoice-" + input.ref }),
});
// → { fileId, url, bytes }: store url in the invoice row, and whoever can read the row can open itThe platform's browser prints A4 (landscape: true for wide pages) with no network and no scripts: put images in as data: URLs. In a workflow, step.pdf(name, html) prints once and records the result.
Your own images, fonts, video, audio and PDFs
assets { "project_id": "…", "action": "upload", "name": "hero.webp", "base64": "…" }
// served at /assets/hero.webp: use it in routes, components, CSS and app.config.ts (brand.icon, brand.ogImage)
storage { "project_id": "…", "action": "upload", "area": "assets", "folder": "media", "url": "https://…/hero.mp4" }
// a clip from a public URL, streamed: served at /assets/media/hero.mp4| Kind | Extensions | Up to |
|---|---|---|
| Images | png, jpg, gif, webp, avif, svg, ico | 10 MB |
| Fonts | woff2, woff, ttf, otf | 10 MB |
| Video | mp4, webm | 100 MB |
| Audio | mp3, m4a, ogg, wav | 25 MB |
| 25 MB | ||
| Text | txt, csv, json, vtt (captions) | 10 MB |
Assets are public. An SVG with scripts or event handlers is refused, and so is a .mov: it plays in Safari only, so convert it to MP4 (H.264 and AAC play everywhere): ffmpeg -i clip.mov -c:v libx264 -c:a aac -movflags +faststart clip.mp4. Video, audio and PDFs are served in byte ranges, so a video seeks and Safari plays it, from Appbricx storage or your own bucket alike; a PDF opens in the browser's viewer. The assets tool takes files up to about 3 MB as base64; upload a bigger one from a URL with the storage tool, from the console's Storage page, or with PUT /api/dev/projects/<id>/assets/<name>.
// A hero clip: muted and playsInline let phones autoplay it; the poster shows until it plays.
<video src="/assets/media/hero.mp4" poster="/assets/media/hero.jpg"
playsInline muted autoPlay loop className="h-full w-full object-cover" />
// One to watch, with captions
<video src="/assets/tour.mp4" poster="/assets/tour.jpg" controls>
<track kind="captions" src="/assets/tour.en.vtt" srcLang="en" label="English" default />
</video>
// A menu or brochure
<a href="/assets/menu.pdf" target="_blank">Menu (PDF)</a>
<iframe src="/assets/menu.pdf" title="Menu" className="h-[80vh] w-full" />Use an MP4, not an animated GIF: it is about a tenth of the size and sharper. The kit's VideoPlayer from @appbricx/kit/primitives draws a player with controls. Fonts can also come from npm: appbricx add @fontsource/inter, then @import "@fontsource/inter/400.css"; in styles/.
Folders, backups and your own bucket
The console's Storage page holds a project's files, assets and database backups, with what each takes up. Files and assets go in folders: an asset's folder is part of its address (/assets/images/hero.png); a file's only organises it, and its /media address never changes when it moves.
Files, assets, backups and exports live in Appbricx storage unless a workspace, or one project, keeps them in a bucket of its own: Cloudflare R2, Amazon S3 or any S3-compatible service. A workspace owner or admin sets it in the console (Workspace settings, Storage, or the project's Storage, Bucket):
- Saving tests the bucket first: a put, read and delete, with a clear reason when one is refused.
- Existing files are copied over in the background. Until the copy finishes, reads fall back to the old place and deletes reach both, so no write is lost and a deleted file stays deleted.
- Your pages keep their addresses: the platform serves
/mediaand/assetsfrom wherever the file is. - Release bundles and verify screenshots stay on the platform, so a slow or revoked bucket never takes your pages down.
Agents manage the files with the storage tool: list, read, upload (from base64, text or a URL), move, folders and permissions. No tool reads or sets the bucket or its credentials.
Check it
screenshot { "project_id": "…", "route": "/tickets/<id>", "as": "member" } // the photo, as the owner
screenshot { "project_id": "…", "route": "/tickets/<id>", "as": "guest" } // and as someone who mustn't see it
assets { "project_id": "…" } // what is served under /assetsGotchas
- Uploads are up to 25 MB each unless the platform's operator sets another limit. Assets have their own limits (above).
- Uploaded files can be public. They start private; a row guests can read, or
read: ["any"], shows them to signed-out visitors. - Seed file columns as null. A seed can't upload; attach files from the app.
- Uploads run in the browser only, never during the server render: call
uploadfrom an event handler. - Store the id, not the URL, in a
ctx.imageorctx.filecolumn: the column holds a uuid.