Assets API
Assets are the bytes a collection holds beside its records: PDFs, images, a dataset’s attachments. Each is named by the SHA-256 of its bytes, ul:asset:<hex>, so identical bytes are stored only once. Upload assets before committing a version whose records attach them.
Workflow
- Compute the SHA-256 hash of your asset locally
- Open a push session that declares the asset in
assets.add; itsneeded_assetslists the declared assets this collection doesn’t hold yet (see Versions) - Upload each needed asset with
PUT(up to 32 MiB) or a direct upload (larger) - Attach it in records as
{"$asset": "ul:asset:<hex>"} - Commit the version. The server checks that this collection holds every attached asset
Every collection uploads the bytes of its assets itself, even when the server already has the same bytes for another collection. This is proof of possession: a hash alone never lets a collection use, or learn about, another collection’s asset.
HEAD /api/collections/:owner/:slug/assets/:hash
Access follows the collection’s visibility
Check whether you can read an asset through this collection. Returns headers only, no body. Anyone who can read the collection can read an asset that any of its versions names. Members can also read assets uploaded to this collection and verified, before any version names them. To learn what to upload, use needed_assets from opening a push session.
Parameters
:hash | SHA-256 hash: bare hex, or prefixed with ul:asset: |
Response
200 | The asset is readable. Content-Length and Content-Type headers set. |
404 | Not found, not readable by you, or a private collection you aren’t a member of. An asset you can’t read is 404 even when it has been withheld. |
451 | The asset is readable by you but has been withheld. |
Example
curl -I https://www.underlay.org/api/collections/kf/archive/assets/ul:asset:a1b2c3...
# HTTP/2 200
# Content-Length: 1048576
# Content-Type: application/pdfGET /api/collections/:owner/:slug/assets/:hash
Access follows the collection’s visibility
Download an asset. After an access check in the context of this collection, the endpoint 302-redirects to a short-lived, presigned storage URL; follow the redirect (e.g. curl -L) to fetch the bytes. The same assets are readable as for HEAD: for anyone who can read the collection, the assets its versions name, and for members (a session, a key, or a share/agent token sent as a Bearer header or ?token=) also assets uploaded to it and not yet in a version. Inaccessible assets return 404, withheld or not; a readable asset that has been withheld returns 451.
The presigned URL lasts 300 seconds and downloads the asset as an attachment, with the collection’s mediaType for it. It’s saved under its hash, or under ?fileName= when you give one, such as an asset reference’s fileName (no /, \, control characters, or bidirectional formatting characters, not . or .., at most 255 characters; anything else is ignored). A name that a system runs when it’s opened, such as .exe, .bat, or .sh, is ignored too. An asset uploaded but not yet committed is named the same way. A type a browser would render or run (HTML, SVG, XML, JavaScript) is sent as application/octet-stream. The redirect carries Cache-Control: private, max-age=240, so a browser may reuse it until shortly before the URL expires. This API path is the durable locator for the asset; the redirect target is ephemeral and must not be persisted or shared, so always re-fetch through the API path. To resolve many assets in one request, see the presign endpoint below. Downloading an asset by its hash alone, outside a collection (GET /api/collections/assets/:hash), is not available yet.
Example
# -L follows the 302 redirect to the short-lived presigned URL;
# -J saves it under the name ?fileName= gives
curl -L -J -O \
"https://www.underlay.org/api/collections/kf/archive/assets/ul:asset:a1b2c3...?fileName=paper.pdf"POST /api/collections/:owner/:slug/assets/presign
Access follows the collection’s visibility
Presign up to 500 assets in one request (more is 400). The response maps each hash, exactly as sent, to a presigned URL (300 seconds), or to null when the hash is invalid, the asset is not readable through this collection, or it has been withheld. Same access model as the single download; avoids one round-trip per asset.
Request
{ "hashes": ["ul:asset:a1b2c3...", "ul:asset:f6e5d4..."] }Response 200
{
"ul:asset:a1b2c3...": "https://storage.example/...",
"ul:asset:f6e5d4...": null
}PUT /api/collections/:owner/:slug/assets/:hash
Auth: write access
Upload an asset of up to 32 MiB. The server verifies that the SHA-256 hash of the uploaded bytes matches the hash in the URL, then records that this collection holds the asset. The bytes are always required, even when the server already has them.
Request
Send the bytes as the raw request body with the appropriate Content-Type header, or as multipart/form-data with the bytes in an asset part. HTML, XHTML, SVG, and XML types are stored as application/octet-stream.
# Compute hash
HASH=$(shasum -a 256 paper.pdf | cut -d' ' -f1)
# Upload
curl -X PUT \
"https://www.underlay.org/api/collections/kf/archive/assets/$HASH" \
-H "Authorization: Bearer $KEY" \
-H "Content-Type: application/pdf" \
--data-binary @paper.pdfResponse 201
{
"hash": "a1b2c3d4e5f6...",
"status": "stored",
"size": 1048576
}Errors
400 | Not a SHA-256 hash; a multipart body with no asset part; or a hash mismatch, where the uploaded bytes don’t match the hash in the URL: {"error": "Hash mismatch", "expected": "..."}. |
413 | Over 32 MiB. Use a direct upload (POST .../assets/uploads). |
POST /api/collections/:owner/:slug/assets/uploads
Auth: write access
Start a direct upload to storage, for assets over the 32 MiB the PUT above takes. An asset is at most 5 TiB (larger: 413); a missing hash or size is 400.
Request
{
"hash": "a1b2c3d4e5f6...",
"size": 21474836480,
"mediaType": "video/mp4"
}Response 201
Up to 5 GiB, the ticket has one presigned url to PUT the bytes to, valid for an hour:
{
"id": "uuid",
"url": "https://storage.example/...",
"expiresIn": 3600
}Larger assets are multipart. The ticket gives partBytes (every part but the last is that long: at least 100 MiB, more when needed to fit), partCount (at most 10,000), and presigned parts for the first 100 parts. Each part URL is valid for an hour.
{
"id": "uuid",
"partBytes": 104857600,
"partCount": 205,
"parts": [
{ "partNumber": 1, "url": "https://storage.example/..." },
{ "partNumber": 2, "url": "https://storage.example/..." }
],
"expiresIn": 3600
}GET /api/collections/:owner/:slug/assets/uploads/:id/parts
Auth: write access
The next 100 presigned part URLs of a multipart upload, starting from part ?from=n (default 1). Only while the upload is pending; otherwise 404. Each part’s PUT returns an ETag; keep them for completing.
Response 200
{
"parts": [
{ "partNumber": 101, "url": "https://storage.example/..." }
]
}POST /api/collections/:owner/:slug/assets/uploads/:id/complete
Auth: write access
Finish an upload. A multipart upload sends every part’s number and ETag; a single PUT upload sends no body. A multipart upload without a non-empty parts list is 400. The server then hashes the bytes in the background; poll GET .../assets/uploads/:id until status is verified (or failed, with an error).
Request
{
"parts": [
{ "partNumber": 1, "etag": "\"9b2cf535f27731c974343645a3985328\"" },
{ "partNumber": 2, "etag": "\"6f1ed002ab5595859014ebf0951522d9\"" }
]
}Response 202
{ "id": "uuid", "status": "verifying" }GET /api/collections/:owner/:slug/assets/uploads/:id
Auth: write access
An upload’s state: pending (waiting for the bytes), verifying, verified (this collection now holds the asset), or failed, with the reason in error.
Response 200
{
"id": "uuid",
"hash": "a1b2c3d4e5f6...",
"size": 21474836480,
"status": "verified",
"error": null
}Asset references in records
A record attaches an asset with an asset reference, an object whose $asset is the asset’s ul:asset: id. Give it a mediaType, what the bytes are (application/pdf), and a fileName, what they’re saved as. Any other member is yours:
{
"id": "pub-001",
"type": "Publication",
"data": {
"title": "An Example Paper",
"pdf": {"$asset": "ul:asset:a1b2c3d4e5f6...", "mediaType": "application/pdf",
"fileName": "paper.pdf"},
"thumbnail": {"$asset": "ul:asset:f6e5d4c3b2a1...", "mediaType": "image/webp"}
}
}A reference may be at any depth in a record’s data. Each attached asset must be held by this collection: named by the version the push builds on, or uploaded to it (a PUT or a verified direct upload). An asset that only another collection holds does not count. If any are missing, the commit returns 422 listing up to 100 of them in assetsNeeded, and the session stays open: upload them and commit it again.
The collection serves an asset as the mediaType its records declare, over the Content-Type it was uploaded with, and changing the declared type changes it at the next commit. It is this collection’s type only: another collection holding the same bytes declares its own. A mediaType is a type/subtype (case doesn’t matter; it’s kept in lowercase), with optional parameters in printable ASCII. A mediaType or fileName that isn’t well formed is ignored, not refused.
{
"error": "Missing assets",
"assetsNeeded": ["a1b2c3d4e5f6..."],
"statusCode": 422
}A $asset that is not a ul:asset: id is refused when you push the record (422), with a message such as $asset at /pdf is a sha256: hash: write ul:asset:<hex>. So is an object with both $link and $asset, and so is a $file. Records written before November 2026 used $file; they were rewritten.
{"$link": "ul:asset:<hex>"} names the same asset but only points at it: it attaches nothing, and the asset need not be held here. Use it for an asset in another collection (see Links in records). Wherever a route takes an asset hash, it takes bare hex or a ul:asset: id, assets.add and assets.remove in a push included.
Renamed in November 2026
Until 2026-11-24 the API called assets files. Clients written before then need these changes; the old names now get 404 or 400:
…/files/…routes are…/assets/….- A hash in a path is bare hex or
ul:asset:<hex>; asha256:prefix is refused. - A multipart upload names its part
asset, notfile. fileCountisassetCount,filesNeededisassetsNeeded, a push’sfilesisassets, andmimeTypeismediaType.- The refusal for assets never sent is
Missing assets, notMissing files. - Records attach assets with
$asset;$fileis refused.