Skip to content

Attachments and Storage ​

Native Cloudflare R2 remains the default, with unchanged deployment steps. For another object store, follow the dedicated Custom S3 (Optional) guide.

Enable Attachments ​

  1. Enable R2 for the deployment account in Cloudflare.
  2. Rerun Actions → 00 Deploy Worker.
  3. The workflow reuses or creates cfchat-files and adds the FILES binding.
  4. Test file uploads and avatar changes in the site.

Without R2, text chat can still be deployed, but uploads, attachment reads, and Telegram file synchronization are unavailable. Enable R2 and redeploy to restore them.

If the R2 check fails, verify R2:Edit permission and the Account ID. Only an account without R2 (Cloudflare error 10042) automatically deploys without attachments.

Change Upload Limits ​

Starting in EdgeChat 2.24.0, chat displays ZIP, DOCX, and other ordinary attachments as cards with a type icon, filename, format, and size. Select the card to download the file. PDFs also retain their inline preview.

The 2.24.0 Actions template allows common archives and Office documents by default. If you deploy manually or use a custom list, merge the MIME types you need from that release's wrangler.example.toml into your existing ALLOWED_FILE_TYPES. ZIP commonly uses application/zip or application/x-zip-compressed, and DOCX uses application/vnd.openxmlformats-officedocument.wordprocessingml.document.

From 2.23.0, a super administrator can set the maximum size per file in Storage usage. The setting takes effect for new uploads immediately. Its initial value comes from MAX_FILE_SIZE, which defaults to 20 MiB. This deployment parameter also caps proxied uploads from older clients and custom S3 deployments. To change the proxy ceiling or allowed file types, edit wrangler.example.toml for Actions or wrangler.toml for manual deployments and redeploy.

toml
[vars]
MAX_FILE_SIZE = "10485760"
ALLOWED_FILE_TYPES = "image/,application/pdf,text/"

This allows images, PDFs, and text up to 10 MiB. Edit the existing [vars] fields.

  • Size is in bytes; the default is 20 MiB (20971520).
  • Types match comma-separated MIME prefixes: image/ allows image types, and application/pdf allows PDF.
  • Dangerous MIME types such as HTML, SVG, scripts, and XML remain rejected.
  • An empty list removes the general type filter; an explicit list suits ordinary use.

Same-named GitHub Repository Variables are not read by the current workflow. See Site Configuration.

Browser encryption and direct R2 transfers ​

The web client generates an independent AES-256 key for each attachment and encrypts it in 8 MiB chunks. An authorized browser receives the file key and reads ciphertext directly from private R2, including byte ranges for media playback. The Worker can also decrypt files for older clients and pages without an active service worker. Direct uploads support an administrator-selected limit of up to 1024 MiB.

GitHub Actions, including first deployment. Keep using your existing Cloudflare account ID and deployment token with R2 Edit permission. The workflow provisions or reuses the attachment bucket, configures browser CORS, derives S3 signing credentials from the deployment token, and writes the Worker Secret EDGECHAT_R2_DIRECT through standard input. No additional repository secrets or dashboard steps are required. Rerun the workflow after rotating your deployment token.

On first deployment the workflow also generates an RSA key pair for wrapping file keys and stores it in the Worker Secret EDGECHAT_FILE_WRAPPING. Subsequent runs reuse the pair. Only the public key is returned to browsers.

Manual deployments can run the same script after publishing the Worker. Use the existing Wrangler environment variables CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN. Supply the bucket bound to FILES.

sh
R2_BUCKET_NAME=cfchat-files node .github/scripts/configure-r2-direct.mjs wrangler.toml

Keep the bucket private and retain its lifecycle rule for aborting incomplete multipart uploads. The workflow manages its own CORS rule for cookie-free signed GET and PUT requests and exposes ETag and Content-Range. The default accepts browser requests from any origin to support forks, Routes and custom domains. To restrict origins, optionally set the repository variable EDGECHAT_R2_ORIGINS to a comma-separated list of HTTPS origins. The Worker's signing credential inherits the deployment token's R2 permissions. Browsers receive short-lived URLs scoped to the object and operation. Custom S3 deployments and accounts without R2 skip this step.

Finalization checks ownership, parts and actual object size. A custom client can upload plaintext. The standard reader authenticates each encrypted chunk. A recipient who already has the key and ciphertext retains offline access after revocation. Preserve the original encryption keyring, D1 data and object metadata for existing downloads. Existing attachments require no conversion.

File Cleanup ​

Expired messages queue their files for deletion. Cleanup checks references from messages, avatars, and icons before removing objects. Unreferenced uploads default to one day of retention. See cleanup settings for budgets and batches.

If an older deployment stored a complete site-icon URL, configure SITE_ORIGINS under Site Configuration.

View Usage ​

Storage statistics in the admin panel shows a snapshot grouped by source after a manual scan. The Cloudflare R2 dashboard shows bucket totals and request usage.

Optional Custom S3 ​

Add just one EDGECHAT_S3 Secret. Full setup, optional fields, manual deployment, migration, and rollback instructions are now in Custom S3 (Optional). Native R2 users need no changes.

Built on Cloudflare · Designed for self-hosting