Files API

Signed uploads of users' files, owner-scoped downloads and deletes.

4 endpointsHTTP API referenceGuide: Files guide

On this page
  1. Authentication
  2. Endpoints
  3. POST /files/sign
  4. POST /files/direct
  5. GET /files/:id
  6. DELETE /files/:id

Base URL: your app's origin ($APP_ORIGIN): the dev site (https://dev-<slug>.apps.appbricx.com), the published host or a custom domain. Errors answer { ok: false, error: { code, message } } unless noted. The host decides the environment: the dev site reads and writes the dev database, the published host and custom domains production's.

Authentication

App key + signed-in user
A project key and a signed-in app session (header or cookie). Signed-out callers get 401. Authorization: Bearer $APP_KEYx-appbricx-app-session: $APP_SESSION

Endpoints

Sign an upload

POST/__appbricx/files/sign

Check type and size and mint a signed file id plus the URL to post the file to.

Auth
App key + signed-in user: Authorization: Bearer $APP_KEYx-appbricx-app-session: $APP_SESSION

Body

NameTypeDescription
mimerequiredstringimage/*, application/pdf, text/*, audio/*, video/*, JSON, ZIP, XML or Office types.
sizerequirednumberBytes (25 MB max by default).

Response

Response
{
  "ok": true,
  "fileId": "0e6f…",
  "uploadUrl": "/__appbricx/files/direct?fileId=0e6f…&sig=…&mime=image%2Fpng",
  "method": "POST"
}

Errors

StatusCodeWhen
401UNAUTHORIZEDMissing or invalid Authorization bearer.
401noneNot signed in.
415MIME_NOT_ALLOWEDType not allowed.
400INVALID_SIZEsize missing or zero.
413TOO_LARGEOver the limit.
429(rate limit)Too many uploads.
curl
curl -X POST "$APP_ORIGIN/__appbricx/files/sign" \
  -H "Authorization: Bearer $APP_KEY" \
  -H "x-appbricx-app-session: $APP_SESSION" \
  -H "content-type: application/json" \
  -d '{"mime":"image/png","size":182044}'
fetch
const res = await fetch(`${APP_ORIGIN}/__appbricx/files/sign`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${APP_KEY}`,
    "x-appbricx-app-session": APP_SESSION,
    "content-type": "application/json",
  },
  body: JSON.stringify({
    "mime": "image/png",
    "size": 182044
  }),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);

Source: internal/svc/runtime/files/files.go:149

Upload a file

POST/__appbricx/files/direct

multipart/form-data with a file field, to the uploadUrl from /files/sign (a direct post without the signature gets a fresh id).

Auth
App key + signed-in user: Authorization: Bearer $APP_KEYx-appbricx-app-session: $APP_SESSION

Query parameters

NameTypeDescription
fileIdoptionalstringFrom /files/sign.
sigoptionalstringFrom /files/sign.
mimeoptionalstringFallback type.

Body

NameTypeDescription
filerequiredFileThe file.

Response

Response
{
  "ok": true,
  "fileId": "0e6f…",
  "size": 182044,
  "mime": "image/png",
  "originalName": "avatar.png"
}

Errors

StatusCodeWhen
401UNAUTHORIZEDMissing or invalid Authorization bearer.
400INVALID_MULTIPARTNot multipart.
400MISSING_FILENo file field.
415MIME_NOT_ALLOWEDType not allowed.
413TOO_LARGEOver the limit.
500STORAGE_ERRORObject store write failed.
500META_INSERT_FAILEDMetadata write failed (the object is removed).
curl
curl -X POST "$APP_ORIGIN/__appbricx/files/direct?fileId=0e6f%E2%80%A6&sig=%E2%80%A6" \
  -H "Authorization: Bearer $APP_KEY" \
  -H "x-appbricx-app-session: $APP_SESSION" \
  -F "file=@avatar.png"
fetch
const res = await fetch(`${APP_ORIGIN}/__appbricx/files/direct?fileId=0e6f%E2%80%A6&sig=%E2%80%A6`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${APP_KEY}`,
    "x-appbricx-app-session": APP_SESSION,
  },
  body: form, // const form = new FormData(); form.append("file", file);
});
const data = await res.json();
if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);

Source: internal/svc/runtime/files/files.go:150

Download a file

GET/__appbricx/files/:id

The file's bytes, if the session can see its metadata row. Images and PDF are served inline; anything else as an attachment, always with nosniff and a sandboxing CSP.

Auth
App key + signed-in user: Authorization: Bearer $APP_KEYx-appbricx-app-session: $APP_SESSION

Path parameters

NameTypeDescription
:idrequiredstringThe file id.

Query parameters

NameTypeDescription
envoptional"dev" | "prod"The environment the file was uploaded to (app.upload puts it in the URL).

Response

Response
<bytes> (content-type: image/png)

Errors

StatusCodeWhen
400INVALID_IDNot a uuid.
404NOT_FOUNDMissing, deleted, or not visible to this user.
curl
curl "$APP_ORIGIN/__appbricx/files/0e6f…?env=prod" \
  -H "Authorization: Bearer $APP_KEY" \
  -H "x-appbricx-app-session: $APP_SESSION"
fetch
const res = await fetch(`${APP_ORIGIN}/__appbricx/files/0e6f…?env=prod`, {
  headers: {
    Authorization: `Bearer ${APP_KEY}`,
    "x-appbricx-app-session": APP_SESSION,
  },
});
const text = await res.text();

Source: internal/svc/runtime/files/files.go:151

Delete a file

DELETE/__appbricx/files/:id

Soft-delete a file the user owns.

Auth
App key + signed-in user: Authorization: Bearer $APP_KEYx-appbricx-app-session: $APP_SESSION

Path parameters

NameTypeDescription
:idrequiredstringThe file id.

Response

Response
{
  "ok": true
}

Errors

StatusCodeWhen
400INVALID_IDNot a uuid.
500DB_ERRORThe metadata update failed.
curl
curl -X DELETE "$APP_ORIGIN/__appbricx/files/0e6f…" \
  -H "Authorization: Bearer $APP_KEY" \
  -H "x-appbricx-app-session: $APP_SESSION"
fetch
const res = await fetch(`${APP_ORIGIN}/__appbricx/files/0e6f…`, {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${APP_KEY}`,
    "x-appbricx-app-session": APP_SESSION,
  },
});
const data = await res.json();
if (!res.ok) throw new Error(data.error?.message ?? data.error ?? res.statusText);

Source: internal/svc/runtime/files/files.go:152