Skip to content

Files

Part of the Server API — not a stable public interface yet; see the note there.

A field that holds a file has an address of its own under its item:

GET /api/{collection}/{id}/files/{field} The file
PUT /api/{collection}/{id}/files/{field} Stores a new file in the field
DELETE /api/{collection}/{id}/files/{field} Empties the field
Collection Fields
modules, campaigns image, banner — images
assets resource — an image or a video
maps image, floor — images; video — a video
tokens, tiles, area-effects asset — the object’s own artwork: an image or a video
entity collections image, token — images

The body of a PUT is the file’s bytes, and its name is suggested in Content-Disposition:

Terminal window
curl -X PUT http://192.168.1.20:8080/api/assets/A1/files/resource \
-H "Authorization: Bearer $KEY" \
-H 'Content-Disposition: attachment; filename="Wooden Door.png"' \
--data-binary @wooden-door.png

Or choose the path yourself:

Terminal window
curl -X PUT "http://192.168.1.20:8080/api/assets/A1/files/resource?path=doors/oak/wooden-door.png" \
-H "Authorization: Bearer $KEY" --data-binary @wooden-door.png
  • The format is read from the bytes, not from Content-Type or the name: PNG, JPEG, GIF or WebP images, MP4 or MOV videos. Anything else is 415, and so is a video sent to a field that takes images. Convert WebM to MP4 first, or import it in the app.
  • The server names the file: the suggested name made address-safe (wooden-door.png), or the item’s slug without one, with the extension the bytes call for. filename* (RFC 5987) is read for names beyond ASCII, and any folders in the name are dropped.
  • A file is never overwritten: a taken name gets a number (wooden-door-2.png), even when it is the field’s own file, since browsers keep artwork by its address.
  • ?path= chooses where the file goes instead, relative to the container’s folder, and is stored as given — Content-Disposition and the field’s usual folder are ignored, and folders are made as needed. It must stay inside the folder (no leading /, no .., no backslash or colon), have no hidden (.git), empty or space-padded parts, and end in an extension the bytes match: .png, .jpg or .jpeg, .gif, .webp, .mp4, .mov (422). Encode spaces as %20.
  • A chosen path that already holds the same bytes is reused, so a script syncing a folder of artwork can run again; one holding anything else is 409 — choose another path, or leave path out to let the server name the file.
  • Assets, maps and map objects’ artwork go at the top of their container’s folder; an entity’s files in its kind’s folder (monsters/goblin-token.png).
  • A token’s, tile’s or area effect’s asset is its own copy of its artwork. An upload creates the copy when the object has none — named after the object — or replaces its file; DELETE deletes the copy, so a token shows its entity’s art again. To use artwork from a module’s assets instead, send assetId.
  • A map’s image or video sets its width and height from the file. A map’s files may be up to 150 MB, every other upload 50 MB.
  • An image larger than 4096 pixels on a side (8192 for a map), or a file that can’t be read as what it starts like, is 422. An asset sent a video becomes a video asset, and one sent a GIF an animatedImage.
  • The file the field held before is deleted when nothing else uses it.
  • PUT and DELETE answer the item with its new ETag, and honour If-Match. An item without the field is 404, as is a GET of an empty field, and a GET of an item the client may not see. The file itself stays at its own address, which isn’t checked.

Pages, and entities’ text, link images by a path relative to their module’s or campaign’s folder (![Cave](images/cave.png)), not through a field. Those files go to the folder itself:

PUT /api/modules/{id}/files?path=… Stores a file at that path in the module’s folder
GET /api/modules/{id}/files Lists the files in the folder

The same for /api/campaigns/{id}/files.

Terminal window
curl -X PUT "http://192.168.1.20:8080/api/modules/M1/files?path=images/cave.png" \
-H "Authorization: Bearer $KEY" --data-binary @cave.png
{ "path": "images/cave.png", "url": "/modules/M1/images/cave.png" }
  • path is required: it is where the file goes and what a page links. It is checked as ?path= is above, and the bytes as any upload’s — images and videos only, so no script or stylesheet can be uploaded this way.
  • 201 with the file’s address in Location when the upload wrote the file; 200 when the path already held the same bytes; 409 when it holds anything else. A file is never overwritten.
  • url is where the web server serves the file, outside /api. A page in the container links path, which resolves to the same file in the app and in a browser.
  • GET answers { entries, total }, each entry { path, url, size, modified }, by path, paged with offset and limit. Hidden files and folders are left out; every other file is listed, whatever its type. The list names the files of hidden content too, so it needs full access: a player or a guest is refused (403, 401).
  • There is no DELETE: nothing records which page or entity links a file, so the server can’t tell whether one is still used. Remove files in the Files app.
  • Uploading needs write, as every write does. MCP agents upload here over REST too.