TrackMe API Docs
Flow guides

Uploads — the fileId Pattern

The two-step upload contract — trade a binary for a fileId at POST /api/v1/uploads, then anchor that fileId on a feature endpoint to make it live.

Every image and document in the app — avatars, truck photos, menu pictures, marketplace listings, review images, community photos, chat attachments, KYC docs, category icons — goes through one ingest endpoint: POST /api/v1/uploads. You send a binary under a typed purpose and get back a fileId (a prefixed ULID like fil_01jq...) plus a urls map of rendered variants. That is step one of two. The upload does nothing visible on its own — the returned fileId must be passed to a separate feature endpoint (the "anchor", e.g. POST /api/v1/me/avatar) before the file is live anywhere.

Audience & auth: this guide is for the Flutter customer and owner apps. Every call requires a Bearer access token — Authorization: Bearer <oat_...>. Anonymous calls return 401 AUTH_REQUIRED. There is no other ingress for binaries: raw image URLs are never accepted by any feature endpoint, so the server controls validation, sizing, re-encoding, and stored variants end-to-end.

Response envelope is always one of:

{ "data": { /* payload */ }, "meta": { "requestId": "req_01..." } }
{ "error": { "code": "AUTH_REQUIRED", "message": "..." }, "meta": { "requestId": "req_01..." } }

Uploading a file does not make it appear anywhere. POST /api/v1/uploads only mints a fileId for a detached / orphan row. The file is invisible to everyone until you pass that fileId to the matching anchor endpoint (POST /me/avatar, the review/community/chat create call, the owner truck/menu/marketplace create-or-update). An upload that is never anchored remains unattached, counts against the per-entity cap, and is shown to no one.

The flow at a glance

Step 1 — Decide purpose and entityId

Pick the purpose for the file (the 10 values are listed below). Then determine entityId:

  • avatar — omit entityId. It defaults to the caller.
  • Existing owned entity (truck_photo, menu_item, menu_category, marketplace, kyc_document) — entityId is the real id of the owned row. The server verifies you own it.
  • Draft-anchored (review_image, community_image, chat_attachment) — the parent row does not exist yet, so you mint a synthetic draft id (any unique 2–50 char string per caller) and reuse it across the uploads that belong to the same future parent.
  • category_icon — admin-gated route; supply the category id.

Step 2 — POST /api/v1/uploads

Send multipart/form-data with purpose + entityId + file. On success you get 201 with { fileId, purpose, entityType, entityId, urls }. The file now exists as an orphan / draft — not live.

Step 3 — Anchor the fileId on a feature endpoint

Pass the fileId (or array of fileIds) to the endpoint that owns the parent: POST /me/avatar, review create, chat send-message, owner truck/menu/marketplace create-or-update. That endpoint re-verifies you uploaded the file, rebinds it to the real parent, and resolves its URLs into the response. Only now is the file visible to other users.

Step 4 — On read, handle URLs by bucket

Public-bucket files (avatars, photos, menus, marketplace, reviews, community) return immutable CDN URLs you can cache forever. Private-bucket files (chat_attachment, kyc_document) are resolved into signed URLs valid for 300 seconds at serve time — treat them as short-lived and refresh them; never cache one long-term.

Step 2 in detail — POST /api/v1/uploads

POST /api/v1/uploads
Authorization: Bearer oat_01jq...
Content-Type: multipart/form-data; boundary=...

purpose=avatar
file=<binary jpg/png/webp>

For a non-avatar purpose you MUST include entityId:

POST /api/v1/uploads
Authorization: Bearer oat_01jq...
Content-Type: multipart/form-data; boundary=...

purpose=truck_photo
entityId=trk_01jq...
file=<binary jpg/png/webp>

Success — 201 Created:

{
  "data": {
    "fileId": "fil_01jq8z...",
    "purpose": "avatar",
    "entityType": "user",
    "entityId": "usr_01jq...",
    "urls": {
      "original": "https://cdn.example.com/user/usr_01jq.../original-01jq....webp",
      "thumb": "https://cdn.example.com/user/usr_01jq.../thumb-01jq....webp",
      "medium": "https://cdn.example.com/user/usr_01jq.../medium-01jq....webp"
    }
  },
  "meta": { "requestId": "req_01..." }
}

The 10 purposes

There are two passes of validation. A generic outer gate (Vine) caps the raw upload at 60MB and the extension to jpg/jpeg/png/webp/pdf. Then a second, per-purpose pass enforces the real size/MIME/cap rules below — so a 4MB avatar passes the outer gate but fails the per-purpose check.

purposeBucketMax sizeAllowed typesVariants returnedCap per entityentityId
avatarpublic (CDN)2 MBjpg/png/webpthumb, medium1omit (defaults to caller)
truck_photopublic (CDN)5 MBjpg/png/webpthumb, medium, large10real truck id (you own)
menu_itempublic (CDN)3 MBjpg/png/webpthumb, medium1real menu-item id (you own)
menu_categorypublic (CDN)3 MBjpg/png/webpthumb, medium1real menu-category id (you own)
marketplacepublic (CDN)5 MBjpg/png/webpthumb, medium, large8real listing id (you own)
review_imagepublic (CDN)3 MBjpg/png/webpthumb, medium3synthetic draft id
community_imagepublic (CDN)5 MBjpg/png/webpthumb, medium, large4synthetic draft id
category_iconpublic (CDN)512 KBjpg/png/webpthumb1category id (admin route)
chat_attachmentprivate (signed URLs)10 MBjpg/png/webp + pdfimage: original, thumb · pdf: original10synthetic draft id
kyc_documentprivate (signed URLs)10 MBjpg/png + pdforiginal only (no variants)5real owner-profile id (you own)

urls always contains original; the other keys vary by purpose. Read the keys that are present — never hardcode that thumb/medium/large exist.

What the server does on ingest

  1. Validates size against the per-purpose limit, MIME against the wire content-type, and runs a magic-byte check — a renamed .pdf served as .jpg is rejected with 409 CONFLICT + code: UPLOAD_MAGIC_MISMATCH.
  2. Authorizes ownership of the target (403 if you do not own it).
  3. Enforces the per-entity cap (409 UPLOAD_LIMIT_REACHED).
  4. For images it re-encodes the original to WebP (stripping any polyglot payload) and generates the configured variants. PDFs and KYC docs pass through untouched.
  5. Writes to the public CDN bucket or the private signed-URL bucket per purpose. On any partial failure it cleans up every S3 object it already wrote.

Private-bucket urls are storage KEYS, not links. For chat_attachment and kyc_document, the urls map returned by POST /uploads contains storage keys (e.g. message/<draftId>/original-....webp), not openable URLs — do not try to GET them. The feature endpoint that resolves the file mints the actual signed URLs (300s TTL) at serve time.

Upload errors

HTTPerror.codeWhen
401AUTH_REQUIREDNo / invalid Bearer token.
403FORBIDDENYou do not own the target entity.
409CONFLICT + code: UPLOAD_TOO_LARGEOver the per-purpose size limit (passed the 60MB outer gate).
409CONFLICT + code: UPLOAD_MIME_REJECTEDType not allowed for this purpose (e.g. a PDF for truck_photo).
409CONFLICT + code: UPLOAD_MAGIC_MISMATCHFile bytes do not match the declared MIME (renamed extension).
409CONFLICT + code: UPLOAD_LIMIT_REACHEDPer-entity cap would be exceeded.
409CONFLICT + code: UPLOAD_FAILEDUpload wasn't staged to disk.
422VALIDATION_ERROR (field=entityId)Missing entityId for a non-avatar purpose.
422VALIDATION_ERROR (field=file)Fails the outer Vine gate — over 60MB, or extension outside jpg/jpeg/png/webp/pdf.

Step 3 in detail — anchoring (example: avatar)

The anchor endpoint takes the fileId you got from step 2, re-checks you uploaded it and that the purpose matches, pins it on the parent, and resolves the URLs into the response.

POST /api/v1/me/avatar
Authorization: Bearer oat_01jq...
Content-Type: application/json

{ "fileId": "fil_01jq8z..." }
{
  "data": {
    "avatarFileId": "fil_01jq8z...",
    "avatar": {
      "original": "https://cdn.example.com/user/usr_01jq.../original-....webp",
      "thumb": "https://cdn.example.com/user/usr_01jq.../thumb-....webp",
      "medium": "https://cdn.example.com/user/usr_01jq.../medium-....webp"
    }
  },
  "meta": { "requestId": "req_01..." }
}

POST /me/avatar is just one anchor. The same fileId-passing contract is used by the create/update endpoints under Reviews, Community, Chats, and Owner (Trucks / Menu / Marketplace), and Profile — each documented under its own tag. Two things every anchor re-checks:

  • Same uploader. You cannot upload a fileId on one account and anchor it on another — that returns 403 FILE_NOT_OWNED.
  • Purpose match. The file's purpose must match what the anchor expects, or you get 409 FILE_PURPOSE_MISMATCH.

Draft-anchored purposes (review / community / chat)

For review_image, community_image, and chat_attachment the parent row does not exist at upload time. You invent a synthetic draft id, upload one or more files against it, then pass the resulting fileIds into the create call:

POST /api/v1/uploads
purpose=review_image
entityId=draft_review_a91f
file=<binary>
POST /api/v1/uploads
purpose=review_image
entityId=draft_review_a91f
file=<binary>

Then create the review with the collected ids (shape documented under the Reviews tag):

POST /api/v1/trucks/trk_01jq.../reviews
Content-Type: application/json

{ "rating": 5, "comment": "...", "fileIds": ["fil_01jq...", "fil_01jq..."] }

The create call rebinds each file's entity_id from your draft id to the real review id, re-checks the per-entity cap, and assigns sort_order from the array order. Use a fresh unique draft id per parent — reusing one risks colliding with another draft's cap bucket.

Lifecycle

A files row moves through these states:

StateMeaningHow you got hereWhat's allowed next
orphan / draftRow exists, processing_status=completed, but nothing references it. entity_id is your own id (avatar) or a synthetic draft id (review/community/chat).POST /api/v1/uploads succeeded.Anchor it on a feature endpoint, or leave it unattached within the per-purpose cap.
attached / liveThe parent row references it; visible to other users.The anchor / create endpoint rebound entity_id to the real parent and pinned the file.Re-order or replace via an update; remove via update or parent destroy.
soft-deleteddeleted_at is set; no longer resolved.Omitted from an update's fileIds set, or the parent entity was destroyed (cascade detaches all files).Terminal — upload a fresh file to replace it.

The model also defines processing_status of pending / failed, but the synchronous pipeline always persists rows as completed; those statuses are reserved by the schema and not surfaced in the happy path.

Transitions

  • (no file) → orphan / draft — POST /api/v1/uploads (authenticated customer or owner).
  • orphan / draft → attached / live — the feature/anchor endpoint that accepts the fileId (must be the same uploader).
  • attached / live → attached / live (re-ordered / set changed) — an update endpoint with a full-replacement fileIds array (owner of the parent).
  • attached / live → soft-deleted — removed from an update's fileIds set, or parent entity destroy (cascade).

Owner updates use full-replacement (diff-attach) semantics. Update endpoints take the complete desired fileIds array, not a delta. Ids you omit get soft-deleted; the array order becomes the display sort order. To add one image you must resend the existing ids plus the new one. To remove all images, send an empty array.

Implementation Notes

Integration issueCorrect handling
Uploading and expecting the file to appear (avatar still blank, photo missing from the truck).The upload only mints a fileId. Anchor it on the feature endpoint (POST /me/avatar, review/community/chat create, owner create-or-update) — that's what makes it live.
Uploading on account A and anchoring on account B.The anchor re-verifies the same uploader. Upload and anchor with the same token, or you get 403 FILE_NOT_OWNED.
Anchoring a fileId of the wrong purpose.The purpose must match the anchor's expectation, or 409 FILE_PURPOSE_MISMATCH. Upload with the correct purpose for the target.
Omitting entityId for a non-avatar purpose.Only avatar defaults entityId. Everything else (including the draft-anchored purposes) returns 422 VALIDATION_ERROR with field=entityId. Supply the real id or your own draft id.
Trying to GET the private-bucket urls from an upload.Those are storage keys, not links. The feature endpoint resolves them into signed URLs (300s TTL). Do not GET upload-time keys directly.
Caching a chat/KYC signed URL.Signed URLs expire in 300 seconds. Refresh them — re-resolve via the feature read endpoint instead of caching.
Expecting the original of an image to be your exact bytes.Public images are re-encoded to WebP; original is the re-encoded WebP, not your upload byte-for-byte. KYC and PDFs are preserved as-is (no re-encode, no variants).
Hardcoding thumb/medium/large.The variant set depends on the purpose (see the table). Always read the keys actually present in urls.
Sending only the new id on an owner update.Updates are full-replacement. Resend the complete desired array (existing + new), or omitted ids get soft-deleted.
Staging more drafts than the cap before anchoring.Caps are enforced at both upload and attach time. Exceeding either returns 409 UPLOAD_LIMIT_REACHED. Do not pre-stage beyond the per-purpose cap.
Assuming the 60MB / pdf outer gate is the real limit.That's only the first pass. The per-purpose check is stricter (e.g. a 4MB avatar → 409 UPLOAD_TOO_LARGE; a PDF truck_photo passes the outer gate but → 409 UPLOAD_MIME_REJECTED).

On this page