File schema

Learn how to define schemas for uploaded files.

File schemas represent URLs to uploaded files, such as images, music, or video files.

File input

In the user interface, a file schema appears as a file uploader.

Examples

Below are some examples of file schemas:

12345
{
"type": "reference",
"id": "@croct/file",
"properties": {}
}

Unlike other schemas, the file schema is not a separate type. Instead, it is an extension of the text schema with additional validation for file uploads. That is why you reference it using the @croct/file identifier instead of defining it directly.

Properties

These are the properties available for file schemas:

allowedTypes(optional)
array<string>

The allowed file types, represented as MIME types.

For example, if you only want to allow PNG and JPEG images, you can set this property to ["image/png", "image/jpeg"].

Below is a table with the file types that are currently supported:

File typeExtensions
image/pngpng
image/jpegjpe, jpeg, jpg
image/jp2jp2, jpg2
image/webpwebp
image/gifgif
image/svg+xmlsvg, svgz
image/avifavif
video/mp4mp4, mp4v, mpg4
video/quicktimemov, qt
video/x-webmwebm
audio/mpegm2a, m3a, mp2, mp2a, mp3, mpga
audio/mp4mp4, mp4a
audio/wavwav
audio/x-wavwav
audio/x-ms-wmawma
audio/oggoga, ogg, opus, spx
audio/aacadts, aac
application/jsonjson
text/plaintxt
Default:any type from the table below
minimumSize(optional)
number

The minimum file size in bytes, inclusive. For example, to allow only files larger than 10KB, set this property to 10240.

Default:no minimum
maximumSize(optional)
number

The maximum file size in bytes, inclusive. For example, to allow only files smaller than 1MB, set this property to 1048576.

Default:5242880 bytes (5MB)