# How it works

> From an upload in your app to a file served at the edge, step by step.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://files.docs.sypnia.com/start/how-it-works/

For agents: How Files works: upload to https://<ref>.files.sypnia.com/object/<bucket>/<path> with user token (resumable for big files) → policy check on sypnia_files.objects in the project Postgres (403 if denied) → bytes to S3 or BYO bucket under project prefix, metadata row (bucket, path, size, type, owner, checksum; pending until scan if enabled) → download public via https://<ref>.files.sypnia.app CDN, private via signed URL or token (never cached for others) → image transforms by query params cached at edge. Two hosts: API on files.sypnia.com, content on files.sypnia.app (separate domain for safety).

### 1. Your app asks to upload

The SDK sends the file to `https://<ref>.files.sypnia.com/object/<bucket>/<path>` with the signed-in user's token. For big files it uses the resumable protocol and sends it in parts.

### 2. Files checks your rules

Files reads who the user is from the token, and asks your project's Postgres whether the policies on `sypnia_files.objects` allow this insert for this bucket and path. If not, the answer is `403` and nothing is stored.

### 3. The object is stored

The bytes go to S3 (or your bucket) under the project's prefix; a row in `sypnia_files.objects` records the bucket, path, size, type, owner and a checksum. With scanning on, the row stays `pending` until the scan says `clean`.

### 4. Someone downloads it

A public file is served from `https://<ref>.files.sypnia.app/<bucket>/<path>` through the CDN. A private file is served to whoever the rules allow, with a signed URL or with their token, and never cached for others.

### 5. Images on the way out

`?width=400&format=webp` on an image URL returns a resized copy, made once and cached at the edge.

## Two addresses

| Address                          | For                                                                                                                            |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `https://<ref>.files.sypnia.com` | the API: uploads, listing, policies, signed URLs, the S3 API                                                                   |
| `https://<ref>.files.sypnia.app` | the content: files and image transforms, on a separate domain so an uploaded HTML or SVG file can never touch Sypnia's cookies |
