Skip to content

File Uploads ​

Binary files (images, video, audio, PDFs, fonts, archives, …) are stored in fields of type Bild. They are uploaded together with the regular write request of a contribution — there is no separate upload endpoint.

Supported Routes ​

MethodPathPayload
PUT/api/item/:chapter?single object — create a contribution
POST/api/item/:idsingle object — complete update
PATCH/api/item/:idsingle object — partial update
PUT/api/collection/:chapter?array (max 50) — bulk create
PATCH/api/collection/:chapter?array (max 50) — bulk partial update

POST/PATCH /api/collection/:any/:id are aliases of the item routes. All routes require a JWT.

Request Format ​

Send the request as multipart/form-data with these parts:

Form fieldRequiredContent
payloadyesThe JSON body of the request, as a string — exactly what you would send as application/json (an object for item routes, an array for collection routes).
filesfor upload / replaceThe binary file. Repeat the field for several files (files, files, …).
  • Only the field name files is accepted for binaries; files in any other form field are rejected.
  • If payload is missing the request fails with "Multipart Uploads (form-data) require the JSON request as value of the key 'payload'"; invalid JSON fails with "Failed to parse the payload. Not Valid Json."
  • Requests without files can still be sent as plain application/json.
  • Files are held in memory and must not exceed 1000 MB each.
  • The MIME type reported by the client must be one of the allowed types; otherwise the request is rejected with 400 Invalid file type ….

Referencing Files from the Payload ​

The value of a Bild field in payload.fields is an array of asset operations. Each operation names an asset by its key:

json
{
  "fields": {
    "Image": [
      {"key": "photo.jpg", "action": "upload", "captions": ["Caption", "Credit"]}
    ]
  }
}

A file part is matched by its original file name (the filename of the multipart part, e.g. what curl -F "files=@./photo.jpg" sends as photo.jpg). The match is exact and happens before sanitizing. All files of a request form one pool, so in bulk requests any item and any field can reference any uploaded file — use unique file names within a request.

Operation Properties ​

PropertyTypeDescription
keystringRequired. For upload: the file name of the multipart part. For all other actions: the stored key of an existing asset (as returned in key by GET).
actionenumupload, replace, rename, delete, duplicate. When omitted, the operation acts like rename.
captionsarrayCaption strings, one per caption variant configured on the field (caption_variants).
replaceKeystringreplace only: file name of the multipart part holding the new binary.
thumbnail, processed, params—Required for duplicate (take them from the GET output).
srcstringAccepted and ignored — lets you send back objects as returned by GET.
variantsarrayOperations on the additional binaries of the row — only on fields with the variants option, see Variants.

No other properties are allowed. The {data, _meta} wrapper returned by GET with meta enabled is unwrapped automatically.

Actions ​

ActionNeeds a file partEffect
uploadyes, filename = keyStores the file and adds a new asset.
replaceyes, filename = replaceKeySwaps the binary of the existing asset key. The old original, thumbnail and scaled variants are deleted from S3. Captions are updated if given.
renamenoSets the captions of asset key. captions is required.
deletenoRemoves asset key and deletes its files from S3.
duplicatenoCopies asset key including its thumbnail and scaled variants (new keys get a <timestamp>_ prefix). Requires thumbnail, processed and params; otherwise the operation is ignored. Can be used to copy an asset from another contribution.

On PUT (new contributions) only upload and duplicate are meaningful, since the field has no existing assets.

Keeping, Reordering and Mixing Operations ​

  • Existing assets that are not mentioned in the field value are kept unchanged — also on POST. To remove an asset, send an explicit delete.
  • Several operations can be combined in one request and across several Bild fields.
  • Newly uploaded and duplicated assets are placed before the existing ones. Existing assets are sorted by the position of their key in the request; to reorder a field, list all existing keys in the desired order (e.g. with rename and their current captions).
  • Writes to a single item (/api/item/...) are serialized server-side, and the field value is re-read from the database after an upload, so parallel uploads to the same field do not overwrite each other.

Variants ​

With "variants": true in the field configuration, a row can hold additional binaries besides its main file — e.g. a CMYK or responsive version, or a PDF next to an image. Variants have no captions; every variant is stored and scaled exactly like the main file (thumbnail and imagesize versions).

The main file stays the identity of the row: key, src, thumbnail, processed and params of a row still describe it, so clients that don't know about variants keep working. GET additionally returns a variants array per row:

json
{
  "key": "photo.jpg",
  "src": "…/photo.jpg",
  "captions": ["Caption"],
  "thumbnail": "…/thumbnail_photo.jpg",
  "processed": ["…/800x0_photo.jpg"],
  "params": {"width": 4000, "height": 3000, "mime": "image/jpeg"},
  "variants": [
    {"key": "photo-cmyk.tif", "src": "…/photo-cmyk.tif", "thumbnail": "…/thumbnail_photo-cmyk.tif.jpg", "processed": ["…/800x0_photo-cmyk.tif.jpg"], "params": {"width": 4000, "height": 3000, "mime": "image/tiff"}}
  ]
}

Variant operations are nested in the operation of their row, under variants. Each one names a variant by key and supports these actions:

ActionNeeds a file partEffect
uploadyes, filename = keyAdds a variant (appended at the end).
replaceyes, filename = replaceKeySwaps the binary of variant key; the old files are deleted from S3.
deletenoRemoves variant key and deletes its files from S3.
duplicatenoCopies variant key (requires thumbnail, processed and params).

Variants that are not mentioned, or mentioned without an action, are kept — sending rows back as returned by GET changes nothing. On a new row (upload or duplicate of the row) variants without an action are copied, so duplicating a row or a contribution includes its variants.

A row operation that only carries variants (no action, no captions) leaves the captions untouched. Replacing the main file keeps the variants; deleting the row deletes its variants as well.

bash
# Add a PDF to an existing row and delete one of its variants
curl -X PATCH http://localhost:8080/api/item/42 \
  -H "Authorization: Bearer JWT_TOKEN" \
  -F 'payload={"fields": {"Images": [
        {"key": "photo.jpg", "variants": [
          {"key": "photo.pdf", "action": "upload"},
          {"key": "photo-cmyk.tif", "action": "delete"}
        ]}
      ]}}' \
  -F "files=@./photo.pdf"

Fields without the variants option can't get new variants: upload, replace and duplicate variant operations are rejected. Rows without variants keep their stored data and output unchanged (no variants property).

Switching the option off is not destructive: variants stored while it was on stay in the output of their rows, are kept when rows are sent back as returned by GET, can still be deleted, and are copied when their row is duplicated. They are removed from S3 when their row or contribution is deleted. The output schema therefore always declares variants, as a required property with the option and an optional one without it.

Storage and Processing ​

For every uploaded file the server:

  1. Sanitizes the file name: accents removed, lower-cased, every character other than a-z 0-9 - _ replaced by - (e.g. Mein Foto (1).JPG → mein-foto-1.jpg). If the name already exists in the bucket, a timestamp is appended (photo_1727170000000.jpg). The resulting name becomes the asset's key.
  2. Stores the original in S3 under the database-specific folder.
  3. Creates a thumbnail thumbnail_<key>.jpg (100 px wide JPEG).
  4. Creates scaled variants <width>x<height>_<key> for each entry in the field's imagesize configuration (fit: inside; a width or height of 0 means auto). Images are auto-rotated according to EXIF orientation. Variants keep the source format, except TIFF which is converted to JPEG (.jpg appended).
  5. Reads image metadata into params (width, height, channels, bits, mime).

Files that are not images (PDF, video, audio, …) get a generated placeholder thumbnail, no scaled variants and empty params.

Deleting a contribution (item or bulk delete) removes all of its assets from S3.

Response ​

POST and PATCH return the new state of every written field in payload:

json
{
  "status": "ok",
  "id": 42,
  "name": "My Entry",
  "payload": {
    "Image": [
      {
        "key": "photo.jpg",
        "src": "https://assets.example.com/.../photo.jpg",
        "captions": ["Caption", "Credit"],
        "thumbnail": "https://assets.example.com/.../thumbnail_photo.jpg",
        "processed": ["https://assets.example.com/.../800x0_photo.jpg"],
        "params": {"width": 4000, "height": 3000, "channels": 3, "bits": "uchar", "mime": "image/jpeg"}
      }
    ]
  }
}

PUT returns {"status": "ok", "id": 123, "name": "..."}; fetch the item to get the asset URLs. The collection routes return an array of these objects, one per item.

Examples ​

bash
# Create an entry with two images
curl -X PUT http://localhost:8080/api/item/Articles \
  -H "Authorization: Bearer JWT_TOKEN" \
  -F 'payload={"name": "Gallery", "fields": {"Images": [
        {"key": "a.jpg", "action": "upload", "captions": ["First"]},
        {"key": "b.png", "action": "upload", "captions": ["Second"]}
      ]}}' \
  -F "files=@./a.jpg" \
  -F "files=@./b.png"
bash
# Replace the binary of an existing asset
curl -X PATCH http://localhost:8080/api/item/42 \
  -H "Authorization: Bearer JWT_TOKEN" \
  -F 'payload={"fields": {"Images": [
        {"key": "a.jpg", "action": "replace", "replaceKey": "a-v2.jpg"}
      ]}}' \
  -F "files=@./a-v2.jpg"
bash
# Delete an asset — no file needed, plain JSON works
curl -X PATCH http://localhost:8080/api/item/42 \
  -H "Authorization: Bearer JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"fields": {"Images": [{"key": "b.png", "action": "delete"}]}}'
js
// Browser / Node 18+
const form = new FormData()
form.append('payload', JSON.stringify({
  fields: { Images: [{ key: file.name, action: 'upload', captions: ['Caption'] }] }
}))
form.append('files', file, file.name)
await fetch('/api/item/42', {
  method: 'PATCH',
  headers: { Authorization: `Bearer ${jwt}` }, // do not set Content-Type manually
  body: form
})

Allowed MIME Types ​

  • image/jpeg
  • image/jpg
  • image/png
  • image/gif
  • image/avif
  • image/webp
  • image/svg+xml
  • image/tiff
  • image/tif
  • video/quicktime
  • video/mp4
  • video/webm
  • video/mpeg
  • video/ogg
  • video/x-msvideo
  • video/x-matroska
  • video/3gpp
  • audio/mp3
  • audio/mpeg
  • audio/wave
  • audio/wav
  • audio/x-wav
  • audio/x-m4a
  • audio/mp4
  • audio/aac
  • audio/ogg
  • audio/opus
  • audio/flac
  • audio/x-aiff
  • audio/webm
  • application/zip
  • application/x-zip-compressed
  • application/gzip
  • application/x-7z-compressed
  • application/pdf
  • application/epub+zip
  • font/woff
  • font/woff2
  • font/ttf
  • font/otf
  • application/font-woff
  • application/font-woff2
  • application/x-font-ttf
  • application/x-font-otf
  • application/vnd.ms-fontobject
  • model/obj
  • model/stl
  • application/octet-stream