File storage
This page is for operators who choose where the files people attach to requests are kept. It covers the three kinds of storage, the largest file, backups and the previews.
Without a storage, attachments are off. Once there is one, a staff Admin turns on People can attach files on Settings › Integrations (see Attachments). While that is off, nobody can attach files, and files already attached can still be downloaded.
Choosing a storage
Section titled “Choosing a storage”There are three storages: a folder on the server, an S3-compatible bucket and a folder on another server over SFTP. As with email, there are two places to choose one, and the environment wins:
- Settings. A staff Admin picks one in the Attachments card and presses Test and save storage. Adiutor writes a small file there, reads it back and deletes it, and says what went wrong if a step fails (unreachable, keys refused, folder missing), never the server’s own reply. Saving needs the staff Admin’s second step from the last 15 minutes and is in the audit log. Its secrets (the S3 secret key, the SFTP password or private key) are encrypted with the auth secret, never shown again, and kept only for the place they were saved for: another S3 service or key, or another SFTP server, port, user or host key, has to be given them again.
- The environment.
ATTACHMENTS_STORAGEislocal,s3orsftp, with the variables below. Then Settings only shows the storage, without its secrets.ATTACHMENTS_STORAGE=offturns attachments off and keeps staff Admins from choosing a storage.
Why set it yourself: a storage chosen in Settings lets staff Admins make the server connect to any address it can reach (which a server of your own on the local network needs). If you don’t want that, set the storage yourself, or off.
A folder on the server
Section titled “A folder on the server”ATTACHMENTS_STORAGE=local and ATTACHMENTS_DIR, an absolute path to a folder that exists and that the app can write to. It serves one server only, and never Vercel, whose disk doesn’t keep files.
Adiutor puts a marker file, .adiutor-attachments, in the folder. Without it, Adiutor refuses to store, read or delete files there. That way a server started without its folder, or a container without its volume, fails instead of keeping files on a disk that goes away, or taking every file for gone. Only setting the folder up writes the marker, never an upload:
- When you save the storage in Settings, its test writes it.
- When the environment chooses the folder, a staff Admin presses Set up this folder on Settings › Integrations, once the folder is the right one. The tab says when a folder isn’t set up.
Keep the marker with the files.
In Docker, mount a volume on /data/attachments, which the image creates for this. Mount it on the app’s container and on every container that runs the jobs. The Compose file does this for you. With docker run, give the app’s container and the jobs’ -e ATTACHMENTS_STORAGE=local -e ATTACHMENTS_DIR=/data/attachments -v adiutor-attachments:/data/attachments, as in Run it with docker run.
An S3-compatible bucket
Section titled “An S3-compatible bucket”ATTACHMENTS_STORAGE=s3, with:
ATTACHMENTS_S3_ENDPOINT: the service’s address. It must behttpsin production, except for a server on this computer.ATTACHMENTS_S3_REGION: the region requests are signed for (us-east-1when unset).ATTACHMENTS_S3_BUCKETATTACHMENTS_S3_ACCESS_KEY_IDandATTACHMENTS_S3_SECRET_ACCESS_KEYATTACHMENTS_S3_FORCE_PATH_STYLE=truefor a service that puts the bucket in the path rather than the host name.
This works anywhere, and it is the way to keep files on Vercel.
The endpoint and region for some services:
- Cloudflare R2:
https://<account ID>.r2.cloudflarestorage.com, regionauto. - Backblaze B2:
https://s3.<region>.backblazeb2.com, region the bucket’s, such aseu-central-003. - AWS S3:
https://s3.<region>.amazonaws.com, region the bucket’s. - Garage or SeaweedFS on a server of your own: your server’s address, your region or
us-east-1, andATTACHMENTS_S3_FORCE_PATH_STYLE=true.
Keep the bucket private: Adiutor serves every file itself, after checking who may read it. The access key only needs to read, write and delete objects in that bucket.
A folder over SFTP
Section titled “A folder over SFTP”ATTACHMENTS_STORAGE=sftp, with:
ATTACHMENTS_SFTP_HOSTandATTACHMENTS_SFTP_PORT(22 when unset)ATTACHMENTS_SFTP_USERNAMEATTACHMENTS_SFTP_PASSWORDorATTACHMENTS_SFTP_PRIVATE_KEYATTACHMENTS_SFTP_HOST_KEY, requiredATTACHMENTS_SFTP_DIR, an absolute path to a folder that exists. Like the local folder, it is set up with the marker file.
Any server with SSH will do, a storage box or a NAS included, and it works from Vercel too.
The private key is the PEM file in base64, on one line: base64 < key | tr -d '\n' (on Linux, base64 breaks its output into lines unless told not to). Settings takes the PEM text as it is.
Adiutor connects only to the server whose key has the fingerprint in ATTACHMENTS_SFTP_HOST_KEY (SHA256:...), and refuses any other. A server has one key per type, and Adiutor is given its ED25519 key when it has one, else ECDSA, then RSA. Get the fingerprint from the server itself, where an impostor can’t answer for it:
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pubssh-keyscan -p <port> <host> | ssh-keygen -lf - prints them too (with the port in ATTACHMENTS_SFTP_PORT, 22 when it isn’t set), a line for each type of key the server has: the line that counts is the ED25519 one, else ECDSA, else RSA, the key Adiutor is given. A scan can’t tell an impostor from the real server, so compare that line with the server’s own.
How it connects:
- Downloads share one connection, kept for a minute after its last use, so only the first after a quiet spell waits for connecting. An upload has a connection of its own.
- At most 64 files are read at once per server process, 16 of them for one person. That stays well under an SFTP server’s usual limit on open files. A download past the limit waits up to 15 seconds for its turn, then answers 503.
- On a platform that freezes and destroys instances (serverless), set
ClientAliveInterval 30andClientAliveCountMax 3in the SFTP server’ssshd_config. It then ends connections whose instance went away without saying so.
The largest file
Section titled “The largest file”A staff Admin chooses the largest file on Settings › Integrations (10 MB until it is changed). ATTACHMENTS_MAX_FILE_MB wins over it. Either way it is 1 to 50 megabytes, and at most 4 on Vercel, which refuses a larger request body.
Behind a reverse proxy, let it pass request bodies that large to /api/attachments, or the proxy refuses larger uploads before Adiutor sees them. nginx defaults to 1 MB: set client_max_body_size 51m; (see Reverse proxy).
A video is played a part at a time: let the proxy pass the Range header and the 206 answers through. nginx does, unless it is told to cache.
Backups and moving storage
Section titled “Backups and moving storage”Back up the files with the database. A file is found by its row in the database, and a row whose file is gone can’t be downloaded.
Every storage keeps files at the same paths: attachments/<two characters>/<ID>, their previews at previews/<two characters>/<ID> and the large pages of PDFs at pages/<two characters>/<ID>. To move to another storage, copy everything under attachments/, previews/ and pages/ there as it is (with rclone copy, say), then switch the storage.
See Upgrading for the rest of what to back up.
Previews
Section titled “Previews”The previews on the files’ tiles are drawn by Adiutor itself, with nothing to install, and the same way in the Docker image, on a plain server and on Vercel. Drawing takes memory while it runs, at most two previews at a time per server: an image up to about 100 MB for a moment, and the PDF drawer up to 256 MiB, which closes after a minute without a PDF. Leave the app’s container room above what it uses at rest.
Example
Section titled “Example”Adiutor runs at https://adiutor.dev on a plain server, from /srv/adiutor as the user adiutor, and keeps files in a folder outside the app’s folder, so a new checkout never touches them. In .env:
ATTACHMENTS_STORAGE=localATTACHMENTS_DIR=/var/lib/adiutor/attachmentsCreate the folder for that user (sudo install -d -o adiutor -g adiutor -m 750 /var/lib/adiutor/attachments), restart Adiutor (sudo systemctl restart adiutor), and as Alex Admin press Set up this folder on Settings › Integrations. Then turn on People can attach files.
Good to know
Section titled “Good to know”- Files are always served by Adiutor itself, after checking who may read them, never from the bucket or the folder directly.
- Switching the storage doesn’t move the files: copy them first.
- A saved secret is kept only for the place it was saved for, so changing the S3 service or the SFTP server asks for it again.
Related
Section titled “Related”- Attachments in Settings
- Files for the people who attach them
- Docker
- Environment variables
Adiutor's code is released under the MIT License. The Adiutor name and logo aren’t covered by it; see the notice.
Set in Inter and JetBrains Mono, under the SIL Open Font License (Inter, JetBrains Mono).