|
| 1 | +--- |
| 2 | +sidebar_position: 5 |
| 3 | +--- |
| 4 | + |
| 5 | +# File URIs |
| 6 | + |
| 7 | +This document explains the `w3ds://file` URI scheme — a standardised, |
| 8 | +human-readable way to reference and dereference files across the MetaState |
| 9 | +ecosystem. A file attached to or described by a [Meta Envelope](/docs/Infrastructure/eVault) |
| 10 | +can be uniquely addressed and resolved with a consistent URI tied to a user's |
| 11 | +entity name (`ename`) and the envelope's identifier. |
| 12 | + |
| 13 | +## Format |
| 14 | + |
| 15 | +```text |
| 16 | +w3ds://file?id=@<user-ename>/<meta-envelope-id> |
| 17 | +``` |
| 18 | + |
| 19 | +| Component | Description | |
| 20 | +| -------------------- | ------------------------------------------------------------ | |
| 21 | +| `w3ds://` | The scheme. Always lowercase. | |
| 22 | +| `file` | The resource host. Identifies the URI as addressing a file. | |
| 23 | +| `id` | Required query parameter carrying the file's address. | |
| 24 | +| `@<user-ename>` | The owning user's entity name (`ename`), always `@`-prefixed.| |
| 25 | +| `<meta-envelope-id>` | The ID of the Meta Envelope describing the file. | |
| 26 | + |
| 27 | +Example: |
| 28 | + |
| 29 | +```text |
| 30 | +w3ds://file?id=@alice/envelope-abc123 |
| 31 | +``` |
| 32 | + |
| 33 | +## How files are stored |
| 34 | + |
| 35 | +A file uploaded to an [eVault](/docs/Infrastructure/eVault) is: |
| 36 | + |
| 37 | +1. Streamed to object storage (DigitalOcean Spaces, S3-compatible) as a |
| 38 | + `public-read` object. |
| 39 | +2. Recorded as a **File Meta Envelope** (ontology `w3ds-file-v1`) with payload: |
| 40 | + `{ filename, contentType, size, blobKey, publicUrl, uploadedAt }`. |
| 41 | +3. Addressed by a `w3ds://file` URI built from the owner `ename` and the |
| 42 | + Meta Envelope ID. |
| 43 | + |
| 44 | +Uploads are performed through the eVault `uploadFile` GraphQL mutation, which |
| 45 | +takes base64 content and returns the `w3ds://file` URI, the Meta Envelope ID, |
| 46 | +and the public object-storage URL. |
| 47 | + |
| 48 | +## Resolving (dereferencing) a URI |
| 49 | + |
| 50 | +There are two dereferencers. |
| 51 | + |
| 52 | +### HTTP — eVault core |
| 53 | + |
| 54 | +```http |
| 55 | +GET /files/:metaEnvelopeId (header: X-ENAME: @<user-ename>) |
| 56 | +``` |
| 57 | + |
| 58 | +Resolves the File Meta Envelope and responds with a **302 redirect** to the |
| 59 | +file's public object-storage URL. The redirect target is validated to be |
| 60 | +`http(s)` only. |
| 61 | + |
| 62 | +- `400` — missing `X-ENAME` header, malformed ID, or an unsafe stored URL scheme. |
| 63 | +- `404` — no File Meta Envelope for that ID, or it has no public URL. |
| 64 | + |
| 65 | +### Programmatic — web3-adapter |
| 66 | + |
| 67 | +```ts |
| 68 | +import { dereferenceFileUri } from "@web3-adapter/w3ds/resolver"; |
| 69 | + |
| 70 | +const file = await dereferenceFileUri( |
| 71 | + "w3ds://file?id=@alice/abc123", |
| 72 | + evaultClient, |
| 73 | +); |
| 74 | +// => { uri, ename, metaEnvelopeId, publicUrl, filename, contentType, size } |
| 75 | +``` |
| 76 | + |
| 77 | +## Error handling |
| 78 | + |
| 79 | +`parseFileUri` / `dereferenceFileUri` throw a descriptive `InvalidW3dsUriError` |
| 80 | +or `Error` for: |
| 81 | + |
| 82 | +- Malformed URIs (not parseable, empty input). |
| 83 | +- Wrong scheme (not `w3ds:`) or wrong host (not `file`). |
| 84 | +- Missing `id` query parameter. |
| 85 | +- `id` missing the `@<ename>` prefix or the `/<meta-envelope-id>` segment. |
| 86 | +- Empty `ename` or `meta-envelope-id`. |
| 87 | +- A non-existent `ename` (eVault cannot be resolved). |
| 88 | +- A non-existent or non-file Meta Envelope. |
| 89 | + |
| 90 | +## Mapper integration |
| 91 | + |
| 92 | +The [Web3 Adapter](/docs/Infrastructure/Web3-Adapter) exposes a `__file()` |
| 93 | +mapping directive that automatically references files on `toGlobal` and |
| 94 | +dereferences them on `fromGlobal`. See |
| 95 | +[Mapping Rules → File Referencing](/docs/Post%20Platform%20Guide/mapping-rules). |
0 commit comments