Aphex
Schema Types

File

Upload arbitrary files (PDFs, documents, archives) and store them as asset references.

The file type handles uploads of non-image files — PDFs, documents, archives, etc. Like image, uploads are stored as asset references so the same file can be reused across documents.

Definition

import type { FileField } from '@aphexcms/cms-core';
{
  name: 'datasheet',
  type: 'file',
  title: 'Datasheet'
}

Properties

PropertyTypeRequiredDescription
namestringYesField identifier.
type'file'YesMust be 'file'.
titlestringYesLabel shown in the admin UI.
descriptionstringNoHelp text shown below the label.
acceptstring[]NoAllowed MIME types or extensions (e.g. ['application/pdf']).
maxSizenumberNoMax file size in bytes. Defaults to the storage adapter limit.
privatebooleanNoIf true, the asset requires an authenticated session to download.
initialValuestring | () => string | Promise<string>NoDefault asset ID.
validation(Rule) => RuleNoValidation rules (required, custom).

Stored data

Files are stored as a reference to an asset record — the same shape used by image:

{
  _type: 'file',
  asset: {
    _type: 'reference',
    _ref: 'asset-id'
  }
}

The asset record tracks the original filename, MIME type, size, and storage adapter used.

Examples

PDF-only upload

{
  name: 'brochure',
  type: 'file',
  title: 'Brochure',
  accept: ['application/pdf'],
  maxSize: 10 * 1024 * 1024, // 10 MB
  validation: (Rule) => Rule.required()
}

Private download

{
  name: 'contract',
  type: 'file',
  title: 'Signed Contract',
  accept: ['application/pdf', '.docx'],
  private: true
}

Private files are served from /media/[id]/[filename] only if the requester has a valid session for the owning organization.

Edit on GitHub

Last updated on