File schema
Learn how to define schemas for uploaded files.
File schemas represent URLs to uploaded files, such as images, music, or video files.
In the user interface, a file schema appears as a file uploader.
Examples
Below are some examples of file schemas:
{"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 type Extensions image/png png image/jpeg jpe, jpeg, jpg image/jp2 jp2, jpg2 image/webp webp image/gif gif image/svg+xml svg, svgz image/avif avif video/mp4 mp4, mp4v, mpg4 video/quicktime mov, qt video/x-webm webm audio/mpeg m2a, m3a, mp2, mp2a, mp3, mpga audio/mp4 mp4, mp4a audio/wav wav audio/x-wav wav audio/x-ms-wma wma audio/ogg oga, ogg, opus, spx audio/aac adts, aac application/json json text/plain txt 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.
Maximum file sizeThe maximum file size is limited to 5MB, or 5242880 bytes.
Default:5242880 bytes (5MB)