Aphex
Schema Types

Image

Image upload with drag-and-drop, alt text, and asset browser.

The image type handles image uploads. It provides a drag-and-drop upload zone, image preview, alt text editing, and an asset browser for reusing previously uploaded images.

Definition

import type { ImageField } from '@aphexcms/cms-core';
{
  name: 'cover',
  type: 'image',
  title: 'Cover Image'
}

Properties

PropertyTypeRequiredDescription
namestringYesField identifier.
type'image'YesMust be 'image'.
titlestringYesLabel shown in the admin UI.
descriptionstringNoHelp text shown below the label.
acceptstringNoMIME type filter for the file input. Defaults to 'image/*'.
privatebooleanNoIf true, the asset CDN route requires an authenticated session with access to its org.
initialValuestring | () => string | Promise<string>NoDefault value.
validation(Rule) => RuleNoValidation rules.

The type definition also includes hotspot, metadata, and fields properties. These are reserved for future use and are not yet implemented.

Stored Data

Images are stored as a reference to an asset record:

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

The referenced asset stores the actual file metadata (URL, filename, dimensions, alt text, etc.) separately in the assets table.

Examples

Basic image

{
  name: 'photo',
  type: 'image',
  title: 'Photo',
  validation: (Rule) => Rule.required()
}

Restricted file types

{
  name: 'logo',
  type: 'image',
  title: 'Logo',
  accept: 'image/svg+xml,image/png',
  description: 'SVG or PNG only.'
}

Private image

Mark a field private when the image should only be served to authenticated members of the owning organization:

{
  name: 'idScan',
  type: 'image',
  title: 'ID Scan',
  private: true
}

Requests to /media/[id]/[filename] for a private asset return 401 unless the request carries a valid session (or a signed URL).

In a document

const product: SchemaType = {
	type: 'document',
	name: 'product',
	title: 'Product',
	fields: [
		{
			name: 'name',
			type: 'string',
			title: 'Name',
			validation: (Rule) => Rule.required()
		},
		{
			name: 'image',
			type: 'image',
			title: 'Product Image'
		},
		{
			name: 'price',
			type: 'number',
			title: 'Price',
			validation: (Rule) => Rule.required().positive()
		}
	]
};

Validation

Available rules: required(), custom(fn), error(msg), warning(msg), info(msg)

Edit on GitHub

Last updated on