Skip to content

Files options

The files key of protobase.config.ts: where file fields keep their bytes, and how. Every key is optional; without files, the providers a field names default to folders under data/files.

export default defineConfig({
files: {
providers: {
private: { kind: 'local', dir: 'data/files/private' },
public: { kind: 's3', bucket: 'shop-media', endpoint: 'https://<account>.eu.r2.cloudflarestorage.com', region: 'auto', public: true, publicUrl: 'https://media.shop.com' },
},
retention: '7 days',
images: 'sharp',
},
})
  • Type: Record<string, LocalProvider | S3Provider | { kind: 'custom' }>
  • Default: private and public, the folders data/files/private and data/files/public, when a field names them
  • Environment variable: PROTOBASE_FILES_<NAME>, which replaces the provider of that name, or adds one

The providers by name. A name is part of every stored value, so name the role (archive), not the vendor. A field that names a provider the app does not have stops it at start. See Providers.

  • { kind: 'local', dir, public?, publicUrl?, retention?, maxBytes?, maxFiles? }: a folder on local disk, relative to the working directory and created when missing.
  • { kind: 's3', bucket, prefix?, endpoint?, region?, accessKeyId?, secretAccessKey?, public?, publicUrl?, retention?, maxBytes?, maxFiles? }: an S3-compatible bucket. endpoint defaults to AWS; the credentials default to S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY, then AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. See S3-compatible buckets.
  • { kind: 'custom' }: a FileProvider of the project’s own, the default export of files/<name>.ts; a custom provider without its file stops the app at start.

For each of the first two, public serves files to anyone with the link, without a signature, publicUrl is where public files are linked from instead of the app’s own /api/files/<provider>, such as a CDN, retention overrides files.retention, and maxBytes (such as '1 GB') and maxFiles cap what the provider holds. See Limits.

PROTOBASE_FILES_<NAME> describes a provider as a URL, such as PROTOBASE_FILES_ARCHIVE=s3://bucket/prefix?endpoint=…&region=auto or file:///data/files/private?public=1, with its credentials in PROTOBASE_FILES_<NAME>_ACCESS_KEY_ID and PROTOBASE_FILES_<NAME>_SECRET_ACCESS_KEY. RETENTION, SECRET and CLEANUP_MINUTES are settings, never provider names.

export default defineConfig({
files: { providers: { archive: { kind: 's3', bucket: 'archive', prefix: 'invoices' }, scans: { kind: 'custom' } } },
})
  • Type: number | string
  • Default: 1 day; 0 for a public provider
  • Environment variable: PROTOBASE_FILES_RETENTION, which overrides it

How long bytes outlive their last reference, so a restore of the database to an earlier moment still finds its files: milliseconds, or text such as 14 days. A provider’s own retention wins over it. See Deleting files.

export default defineConfig({ files: { retention: '14 days' } })
  • Type: string
  • Default: PROTOBASE_FILES_SECRET, else the app’s secret
  • Environment variable: PROTOBASE_FILES_SECRET

Signs upload tickets and download links. The app does not start with file fields and no secret.

export default defineConfig(({ env }) => ({ files: { secret: env.FILES_SECRET } }))
  • Type: string[]
  • Default: none

Hosts whose images the admin app draws with the page’s referrer, besides the app’s own and those its providers link public files from. Images from any other host load with referrerPolicy="no-referrer". See Image referrers.

export default defineConfig({ files: { trustedHosts: ['images.example.com'] } })
  • Type: Record<string, string[]>
  • Default: none

The app’s own media types, each with its extensions, the first being the one its files are stored with. A file uploaded with such an extension, whose content is no type the server recognizes, is stored and served as that type, and a viewer registered for it opens it in the admin app. An extension may hold dots. A malformed type, a built-in type or a built-in extension stops startup. See Your own types.

export default defineConfig({ files: { types: { 'application/vnd.example.report+json': ['report.json'] } } })
  • Type: { provider?: string; maxFileSize?: number | string } | false
  • Default: { provider: 'private', maxFileSize: '50 MB' }

Where supabase.storage keeps the bytes of its objects, which the app serves at /api/sb/storage/v1 when it has an API key: provider names one of the providers, and maxFileSize caps every upload, as text or a number of bytes; a bucket’s own limit can only be lower. false serves no /api/sb/storage/v1. See Supabase Storage API.

export default defineConfig({ files: { storage: { provider: 'uploads', maxFileSize: '10 MB' } } })
  • Type: 'sharp'
  • Default: none

The image library that makes the variants and placeholders of image fields, by its package name, loaded from the project’s dependencies when the app serves. Fields with .variants() or .placeholder() need it. See Image variants and placeholders.

export default defineConfig({ files: { images: 'sharp' } })