Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

docs: document upload size limits for operators and bots (#3823)

Hampus936fbf477163
diff --git a/fluxer_docs/astro.config.ts b/fluxer_docs/astro.config.ts
index 547b10394..c0d5d6ba2 100644
--- a/fluxer_docs/astro.config.ts
+++ b/fluxer_docs/astro.config.ts
@@ -166,6 +166,7 @@ export default defineConfig({
'operator/running',
'operator/voice-servers',
'operator/reverse-proxy',
+ 'operator/upload-limits',
'operator/sign-in',
'operator/kubernetes',
'operator/docker-compose',
diff --git a/fluxer_docs/src/content/docs/operator/environment.mdx b/fluxer_docs/src/content/docs/operator/environment.mdx
index c76f7d276..c7303dccd 100644
--- a/fluxer_docs/src/content/docs/operator/environment.mdx
+++ b/fluxer_docs/src/content/docs/operator/environment.mdx
@@ -880,7 +880,7 @@ The upload relay URL the API hands to clients. When it's empty, the API uses the
### `FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES`
-The largest upload the relay accepts, in bytes from 1 to 5 GiB. It can't be more than `FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES`. When it's empty, the relay uses `524288000`, which is 500 MiB. With rexctl, use `rexctl config set FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES`.
+The largest single request body the relay accepts, which is one object or one part of a multipart upload, in bytes from 1 to 5 GiB. It can't be more than `FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES`. When it's empty, the relay uses `524288000`, which is 500 MiB. With rexctl, use `rexctl config set FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES`.
### `FLUXER_MEDIA_PROXY_UPLOAD_RELAY_TOKEN_TTL_SECS`
diff --git a/fluxer_docs/src/content/docs/operator/upload-limits.mdx b/fluxer_docs/src/content/docs/operator/upload-limits.mdx
new file mode 100644
index 000000000..7fd57fb57
--- /dev/null
+++ b/fluxer_docs/src/content/docs/operator/upload-limits.mdx
@@ -0,0 +1,36 @@
+---
+# SPDX-License-Identifier: AGPL-3.0-or-later
+title: Upload size limits
+description: Change how large attachments can be for people and bots on your instance.
+sidebar:
+ label: Upload limits
+---
+
+Attachment sizes come from two [limit keys](/http-api/instance/#limit-keys). `max_attachment_file_size` is the largest file anyone can attach. `max_bot_attachment_file_size` is the largest file a bot can attach, and a bot gets the lower of the two. By default, people with premium can attach files up to 500 MiB and people without it up to 25 MiB, and bots can attach files up to 50 MiB.
+
+You can change both keys under Limit Config in the admin panel sidebar or with [Replace limit configuration](/admin-api/instance/#replace-limit-configuration).
+
+## Pick the rule to edit
+
+Which rule to edit depends on the instance's [premium mode](/admin-api/instance/#premium-modes).
+
+| Premium mode | Rule for people | Rule for bots |
+| --- | --- | --- |
+| everyone | `default` | `default` |
+| mirror | `default` for people without premium and `premium` for people with it | `premium` or `default` |
+
+Bots always count as having premium, and when a rule with a filter matches, Fluxer uses the higher of its value and the value from `default`. Raising `max_bot_attachment_file_size` in either rule raises it for every bot.
+
+To raise the bot limit for one bot, give the bot a trait with [Set user traits](/admin-api/users/#set-user-traits) and add a rule for that trait that sets `max_bot_attachment_file_size`. To go above `max_attachment_file_size`, which is 500 MiB for bots by default, set `max_attachment_file_size` in the same rule too. A rule for a trait can raise a limit above the value in `default` but can't lower it.
+
+## Large files and the upload relay
+
+The web and desktop apps upload files to storage before they send the message. Each part is 10 MiB or a twentieth of the file, whichever is larger. When the [upload relay](/media-proxy/upload-relay/) is in use, `FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES` limits each part and not the whole file. With the default of 500 MiB, you only need to raise it for files above about 10 GB.
+
+## Multipart messages
+
+Bots and other clients can also attach files in a multipart message. The API streams each file to storage while it arrives and doesn't keep whole files in memory. When a file goes over its limit, the API stops saving it and reads up to 64 MiB more of the body for up to 30 seconds, so the client is done sending when the error arrives. If more than that is left, the API answers right away and closes the connection, and some clients report a connection reset instead of the error. The whole request has to finish within `FLUXER_API_REQUEST_TIMEOUT_MS`, which is 120 seconds by default. For files of hundreds of MiB, clients should upload first.
+
+`FLUXER_API_MAX_CONCURRENT_FORM_UPLOADS` sets how many files the API streams to storage at once, which is 16 by default. Plan for up to about 25 MiB of memory for each, so the default adds up to about 400 MiB to what the API uses. When all of them are busy, the next file waits up to 10 seconds and then fails with 503 and a `Retry-After` header.
+
+Your proxy's body size limit also applies to multipart messages. The Helm chart sets `nginx.ingress.kubernetes.io/proxy-body-size` to `512m` on its ingress, and the [nginx example](/operator/reverse-proxy/) uses `client_max_body_size 512m`. Uploading first sends each part in its own request, and these limits apply to one part at a time.
diff --git a/fluxer_docs/src/content/docs/topics/uploads.md b/fluxer_docs/src/content/docs/topics/uploads.md
index 9b01ff19b..a045c5e6d 100644
--- a/fluxer_docs/src/content/docs/topics/uploads.md
+++ b/fluxer_docs/src/content/docs/topics/uploads.md
@@ -13,6 +13,16 @@ You can send attachments as `files[n]` parts in a [multipart message](/http-api/
Uploading first needs `presigned_attachment_uploads` set to true in [instance features](/http-api/instance/#instance-features-object). When it is off, the plan and completion requests return 403 `FEATURE_TEMPORARILY_DISABLED`.
+## Choose how to upload
+
+Each file can be up to the [`max_attachment_file_size`](/http-api/instance/#limit-keys) limit. A bot gets the lower of that limit and [`max_bot_attachment_file_size`](/http-api/instance/#limit-keys), which is 52428800 bytes (50 MiB) unless the instance admins change it.
+
+In a multipart message, Fluxer checks each file part while it arrives. When a part goes over the limit, the request fails with 400 `FILE_SIZE_TOO_LARGE`. When `Content-Length` is larger than every allowed file plus the rest of the message, the request fails with 413 `FILE_SIZE_TOO_LARGE` and Fluxer saves none of it. In both cases Fluxer reads up to 64 MiB of the rest of the body before it answers. If more is left, it answers right away and closes the connection, and some HTTP clients then report a connection reset instead of the response. Check file sizes against the limit before you send to avoid this.
+
+When the instance is already streaming many files, a file part can wait up to 10 seconds and then fail with 503 and a `Retry-After` header. A multipart request also has to finish within the instance's request timeout, which is 120 seconds by default.
+
+The web and desktop apps upload files first whenever the instance has `presigned_attachment_uploads` on, and bots should do the same for large files. The bytes go to storage or the upload relay in parts of 10 MiB or more, and the API request timeout doesn't apply to them.
+
## Request an upload plan
Call [Request attachment upload URLs](/http-api/messages/#request-attachment-upload-urls) with up to 10 files, each with its exact byte count. Each file in the plan has an `upload_mode` that decides which fields it gets.
diff --git a/fluxer_rexctl/internal/instance/envvars.go b/fluxer_rexctl/internal/instance/envvars.go
index 729396ede..007f5fc0a 100644
--- a/fluxer_rexctl/internal/instance/envvars.go
+++ b/fluxer_rexctl/internal/instance/envvars.go
@@ -237,7 +237,7 @@ var envVars = []envVar{
{"FLUXER_CLAMAV_FAIL_OPEN", "media", "Whether uploads go through when a ClamAV scan fails, such as when Fluxer can't connect to the scanner or gets no usable answer. Use `true` or `false`. When it's empty, Fluxer rejects the upload."},
{"FLUXER_MEDIA_PROXY_ATTACHMENT_URL_SECRETS_BASE64", "media", "Keys that sign attachment URLs, separated by commas. Each is standard base64 that decodes to at least 32 bytes. The first entry signs and every entry verifies. To rotate keys, add the new key last and restart the stack. Then move it first and restart again. Every process can then verify the new key before any process signs with it. Remove the old key 24 hours later. Removing a key ends the data package links it signed. When it's empty, Fluxer returns unsigned attachment URLs."},
{"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT", "media", "The upload relay URL the API hands to clients. When it's empty, the API uses the public origin followed by /media."},
- {"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES", "media", "The largest upload the relay accepts, in bytes from 1 to 5 GiB. It can't be more than FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES. When it's empty, the relay uses `524288000`, which is 500 MiB."},
+ {"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES", "media", "The largest single request body the relay accepts, which is one object or one part of a multipart upload, in bytes from 1 to 5 GiB. It can't be more than FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES. When it's empty, the relay uses `524288000`, which is 500 MiB."},
{"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_TOKEN_TTL_SECS", "media", "How long an upload relay token stays valid, in seconds. When it's empty, the API uses `900`."},
{"FLUXER_MEDIA_PROXY_UPLOAD_RELAY_KEEP_DIRECT_COUNTRIES", "media", "Two-letter country codes, separated by commas, whose clients upload to the object store directly and skip the relay. It needs the GeoIP database in FLUXER_GEOIP_DB_PATH, and browsers can only upload directly when FLUXER_S3_PUBLIC_ENDPOINT is set. When it's empty or there's no GeoIP database, every client uses the relay and browsers never see the internal store address."},
{"FLUXER_MEDIA_PROXY_CORS_MODE", "media", "Whether the media proxy checks the Origin of media requests. Use `off`, `report` or `enforce`. When it's empty, it's off. With `report`, the media proxy logs requests it would refuse, and with `enforce` it refuses them. A request with no Origin header is always served."},
diff --git a/fluxer_rexctl/internal/stack/files/.env.example b/fluxer_rexctl/internal/stack/files/.env.example
index abd20d72e..2cbd835e8 100644
--- a/fluxer_rexctl/internal/stack/files/.env.example
+++ b/fluxer_rexctl/internal/stack/files/.env.example
@@ -1251,9 +1251,10 @@ FLUXER_VAPID_PRIVATE_KEY=
# rexctl: rexctl config set FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT
# FLUXER_MEDIA_PROXY_UPLOAD_RELAY_ENDPOINT=
-# The largest upload the relay accepts, in bytes from 1 to 5 GiB. It can't be
-# more than FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES. When it's
-# empty, the relay uses 524288000, which is 500 MiB.
+# The largest single request body the relay accepts, which is one object or
+# one part of a multipart upload, in bytes from 1 to 5 GiB. It can't be more
+# than FLUXER_MEDIA_PROXY_UPLOAD_RELAY_SPOOL_MAX_TOTAL_BYTES. When it's empty,
+# the relay uses 524288000, which is 500 MiB.
# rexctl: rexctl config set FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES
# FLUXER_MEDIA_PROXY_UPLOAD_RELAY_MAX_BODY_BYTES=