Files
Upload a user file into the project's object store and store the returned URL in an image or attachment field.
On this page
app.upload
app.uploadmethod
Upload a user file (two steps: /files/sign checks type and size and signs a file id, then the file is posted to /files/direct). Store the returned url in an image or attachment field.
app.upload(file: File): Promise<{ url: string; name: string }>Parameters
| Name | Type | Description |
|---|---|---|
filerequired | File | A browser File, e.g. from an <input type="file">. |
- Returns
- { url, name }. url is /__appbricx/files/<id>?env=<dev|prod> on the app's API origin.
- Errors
- "file uploads aren't available in this preview" without a runtime.
- "That file type isn't allowed." (images, PDF, text, audio, video, JSON, ZIP, XML and Office documents are), "That file is too large." (25 MB by default).
- The server's code when the upload fails: MISSING_FILE, STORAGE_ERROR, META_INSERT_FAILED.
- Permissions
- Needs a signed-in app user. File metadata lives in _appbricx_files with owner row-level security; reading a file back needs a session that can see its row.
async function onPick(e: ChangeEvent<HTMLInputElement>) {
const file = e.target.files?.[0];
if (!file) return;
const { url } = await app.upload(file);
await app.update("members", app.me("member")!, { avatar: url });
}Source: packages/appkit/src/kits/primitives/app-handle.ts:182