Skip to content

Files

A file field collects attachments. What the submission stores is what each file is and where it went — never its bytes:

{
"id": "0193…",
"name": "floor-plan.pdf",
"size": 182344,
"contentType": "application/pdf",
"storageKey": "forms/survey/0193…"
}

A submission read back years later is therefore small, readable on its own, and still says what was attached even if the object store has since been emptied.

A file is offered when somebody asks where to put one — before any bytes exist — stored when they arrive, and claimed when a submission that references it is accepted. Anything that stays unclaimed is rubbish, and is collected after a day.

The rule underneath: the claim happens inside the submission’s own transaction. A submission exists if and only if the files it names belong to it. Two submissions naming the same file are adjudicated by the database rather than by whichever check ran first, because the check made before the transaction passes for both of them.

The row is written before the bytes, too. Bytes with no row are invisible rubbish that nothing will ever look for; a row with no bytes is a broken reference that shows up the moment anybody tries to download it. Only the first is a problem you never find out about.

One request receives a file’s bytes at a time. A second PUT for a file while the first is still being scanned or written is answered 409 busy before its bytes are scanned, and nothing it sent is kept. The file field’s Try again runs your uploader again, and an uploader that offers before it sends, as the admin’s does, gets a new file and never meets this. A second PUT for one file comes from a proxy or HTTP library retrying it, or from an uploader that sends the bytes again without offering again — and the first request holds the file for two minutes at most, so one that dies holding it keeps such a PUT waiting that long. Without this, a second request that finished first could be claimed by a submission and then overwritten by the first arriving late — the row put back to unclaimed, for the collector to delete, and the bytes replaced (0153). A request whose scan and write together take longer than the two minutes is the case this does not close: the row stays with its submission, and its bytes can still replace the ones that were kept. The supplied clamd adapter does not keep a scan inside that: its 30 seconds are of silence, not of the whole scan. That request is answered 409, and nothing else tells it apart — the request log has a 409 on that route, as it has for every other refusal there.

Terminal window
FORMANCY_FILES_DIR=/var/lib/formancy/files
FORMANCY_MAX_FILE_BYTES=10485760 # optional; the operator's ceiling
Variable Required Meaning
FORMANCY_FILES_DIR no Where uploaded bytes go. Unset means this deployment accepts none.
FORMANCY_MAX_FILE_BYTES no The operator’s ceiling over every form’s own maxFileSize, in bytes. Defaults to 10 MB. A whole number from 1 to 2147483647 — the largest size the files table records — or the server does not start.

Leaving it unset is a supported state, not a misconfiguration. A form with a file field still renders and still submits; the field says plainly that there is nowhere to put one. It is deliberately not defaulted, because in a container it has to be a mounted volume, and that is the one thing a self-hoster has to think about.

Set FORMANCY_S3_ENDPOINT and the four settings beside it, and bytes go to an S3-compatible store rather than a local directory:

Terminal window
FORMANCY_S3_ENDPOINT=http://garage:3900
FORMANCY_S3_BUCKET=formancy
FORMANCY_S3_REGION=garage
FORMANCY_S3_ACCESS_KEY_ID=GK…
FORMANCY_S3_SECRET_ACCESS_KEY=…

None of the four is defaulted. A guessed bucket is a deployment that uploads into nothing; guessed credentials are a deployment where every file reads as missing. Both fail at startup instead. Setting this and FORMANCY_FILES_DIR together is also refused, because two stores means files land in one and are looked for in the other.

An empty value counts as unset, for the endpoint and for the directory. That is how the compose files switch stores: they point FORMANCY_FILES_DIR at their volume, and .env blanks it with FORMANCY_FILES_DIR="" — Self-hosting has the block, and the release it needs.

The region is part of the request signature rather than a label: a wrong one is a signature the store computes differently and rejects. Garage answers to whatever its own s3_region says.

Garage is what this is tested against — a real one, in a container, on every run. The same code path serves MinIO, Backblaze B2, Cloudflare R2 and Amazon S3, because the only thing they need in common is SigV4 and path-style addressing.

Bytes still pass through the server. A presigned upload straight from the browser is the eventual shape and is the only way to accept a file larger than the request body cap; this replaces where the bytes land without changing how they arrive, which is what a second replica needs.

At the offer, before a byte is sent. The field’s accept list, its maxFileSize, and the deployment’s ceiling. A browser’s file picker filter is a convenience for the person filling the form in, and nothing at all to somebody posting to the endpoint directly. A size that is not a whole number of bytes — a fraction, a negative — is refused there too; zero is a size. A name or a type with a NUL character in it is refused before the offer is read, 400 nul_character, as a request body with one is anywhere (0173); the bytes themselves may hold NUL bytes like any others.

The offered size is then binding: a different number of bytes is refused, or the size check was only a suggestion.

Not by its type, once it is offered. The bytes are the body of a PUT to the offer’s uploadUrl, under whatever type the file has, and they are kept as they arrive: a .json file is not parsed, a .txt file is not decoded, and neither is refused for not being the request the server expected. That route alone takes any body as bytes; no other route is handed them.

As often as an offer, from one address. Sending the bytes is limited as offering a file is: thirty a minute per address, counted apart from the offers, and answered 429 past that before a byte of the body is read — an offer makes a place for a file, not one attempt at it. While the server cannot count, both go through uncounted (0172). A file’s address with an id the server never hands out — one that is not a uuid — is 404 unknown_file, as a file that is not there is.

Being allowed to submit is not being allowed to upload… and it is the same rule. The upload gate and the submission gate are one function, because a form nobody may submit to is not a form anybody may upload to — otherwise the store is free disk for whoever finds the path.

The storage key is minted, never submitted. A key built from a filename is a path traversal waiting for somebody to try it. The name is kept verbatim because it is what the reader called it, and it is display only.

Authenticated, Content-Disposition: attachment, nosniff, and a sandboxing CSP. Never inline.

Under the name the respondent gave it, whatever that is. A name in plain ASCII is filename="notes.pdf"; one with anything else in it is written twice, readably with _ for each character ASCII cannot hold and exactly, percent-encoded as UTF-8, in filename* — filename="__ _.pdf"; filename*=UTF-8''%E6%97%A5%E6%9C%AC%20%E2%82%AC.pdf for 日本 €.pdf — as RFC 6266 has it, which has a reader that knows filename* prefer it. v0.4.0, and every release from v0.2.0, could not serve a file named outside Latin-1 or with a control character in its name: the download was a 500 (0175).

A separate hostname is the right answer to stored XSS via an uploaded HTML or SVG file, and a single-container deployment has not got one — forcing a download is the accommodation, and it is the one place this deployment model genuinely costs something.

A session is required even for a form anyone may submit to. Being allowed to submit is not being allowed to read what everybody else attached.

The control picks files; something else uploads them and reports back what was stored. That split is the whole design: no formancy package has an opinion about where bytes go, which is what lets the same field work against local disk, S3 or your own service.

import { UploaderProvider } from '@formancy/react'
<UploaderProvider value={upload}>
<FormancyForm />
</UploaderProvider>
import type { Uploader } from '@formancy/react'
const upload: Uploader = async (file, { field, signal, onProgress }) => {
// …put it somewhere, and report what was stored
return { id, name: file.name, size: file.size, contentType: file.type, storageKey }
}

Angular takes the same function through provideFormancyUploader(upload).

The second argument is optional to read. field is the data path of the field the file is for, as a server looks it up — items[].receipt for a file field in any row of a repeater. signal is aborted when the person cancels the file: hand it to fetch and the transfer stops. onProgress(sent, total) draws the file’s progress bar — but fetch cannot report how far an upload has got, so an uploader that wants a figure sends the bytes with XMLHttpRequest and its upload.onprogress. An uploader that ignores all three still works: the bar has no figure, and a cancel stops waiting for the file rather than stopping the transfer.

The field sends one file at a time, in the order they were picked, and shows each: waiting its turn, uploading with how far it has got, or refused with the reason the uploader gave — with Cancel, Try again and Dismiss where they apply. The picker stays open meanwhile, so a second file joins the queue. A failure on one file does not stop the others, and a file that did upload is recorded at once, so nothing that reached storage is left unclaimed while somebody reads a message.

A cancelled upload is not attached, even if the uploader finishes it anyway — the person took it back, and bytes nobody claims are collected after a day.

A file belongs to its row. In a repeater, a row that moves while its file uploads keeps the file: it lands in that row wherever it now is, and in no row if the row was removed.

Attached files can be moved up or down, with the file’s position in the button’s name; the order is the person’s, and it is kept in the answer.

An image picked in this session gets a thumbnail, decoded from its bytes and drawn on a canvas rather than loaded from an object URL — so a page whose Content-Security-Policy does not allow blob: images still shows it. A file stored before the page was opened has none: its bytes are not in the browser, and the renderer knows no address to fetch them from. Without createImageBitmap there is no thumbnail, and the name is shown alone.

What happens to each file is decided once, in @formancy/core, and both renderers draw it (0130).

Rejecting is a real answer. Throw, and the field says so out loud rather than dropping the file — a submission somebody believes carries their evidence and does not is the worst outcome available here.

Without an uploader the field is read-only and says why. That is a supported state too: a form with no file fields needs no uploader, and throwing would turn a form that mostly works into a blank page.

Point the deployment at a ClamAV daemon and every upload is scanned before its bytes are kept:

Terminal window
FORMANCY_CLAMD_HOST=clamav
FORMANCY_CLAMD_PORT=3310 # optional; clamd's own default
FORMANCY_CLAMD_MAX_BYTES=104857600 # optional; clamd's StreamMaxLength

Clean is kept; anything else is not. A finding is refused with the name clamd gives it, and the file field shows that as the reason the file was not attached. A scanner that cannot be reached — not started, restarting, timing out — refuses the file too, and says to try again: a deployment that configured a scanner did so to keep unscanned files out, and its being down is not a reason to let one in. The file field’s Try again is how a person gets past a restart. A refused file is never in the store, and no submission can claim it.

Set AlertExceedsMax yes in clamd.conf. ClamAV’s own configuration says that content past its MaxFileSize or MaxScanSize — an archive that expands too far — is not flagged unless it is set, and its default is off: such a file is answered clean without being scanned. With it, the file is refused as Heuristics.Limits.Exceeded.

FORMANCY_CLAMD_MAX_BYTES is clamd’s StreamMaxLength, 100 MiB unless you changed it. A larger file is refused as one that could not be scanned, before a byte is sent: past that limit clamd closes the connection mid-stream, and its answer can be lost with it.

The scanner is not checked at startup, because clamd takes minutes to load its signatures; until it answers, uploads are refused and everything else works. Keeping the signatures current is the operator’s, as with any scanner. Files stored before a scanner was configured are not rescanned. Without FORMANCY_CLAMD_HOST nothing is scanned — a supported state.

The scanner is a port: a deployment embedding @formancy/server may pass any Scanner to createApp — scan(file, bytes) resolving clean or with a finding, and throwing only when it could not be asked.

What has been verified, and how. The adapter’s tests run against a stand-in that speaks clamd’s protocol; the composition was run once, on 2026-10-09, against ClamAV 1.5.4: a plain document was clean, the EICAR test file was found, and a stream over 100 MiB was refused. That run could not show what clamd does with content past its scan limits — the EICAR file is recognised only as itself, so it cannot be hidden in a larger one — which is why the advice above quotes ClamAV’s configuration rather than a measurement (0131).

  • Resumable or multipart uploads. The deployment ceiling is also the largest single file.
  • A presigned upload path. Bytes go through the server on their way to the object store. Removing it from the data path changes the upload flow end to end, including both renderers, and is what would lift the request-body ceiling.
  • Garage in the supplied compose files. They pass the settings through, and neither runs a store: a fresh Garage node accepts no data until a layout is assigned, which is four commands after the container starts rather than anything a compose file can declare. Point it at a store you run.