Overview

File Schema

s.file()

Generic files. Use s.file for the schema. The content is a plain object with a path and the mimeType read off the file.

NOTE: if you limit the accept to video as the example below, the file will be treated as a video in Val Studio.

Passing a file collection module instead of options - s.file(collectionVal) - turns the field into a picker for that collection. The value is then only the path: the mimeType is stored once, in the collection, and repeating it on the field is a validation error.

Options:
accept: string

The accept value is a comma-separated list of one or more image types, or unique file type specifiers, describing which file types to allow.

s.file({ accept: "video/*" })
Methods:
.validate: method

Custom validation function

.remote: method

Enable remote files

Examples:
const schema = s.file({ accept: "video/*" });
export default c.define("/content/file.val.ts", schema, {
  path: "/public/val/video.mp4", // NOTE: the actual files must be in the public/val folder
  mimeType: "video/mp4",
})
Picking from a collection
import documentsVal from "./documents.val"; // a s.files() module

const schema = s.file(documentsVal);
export default c.define("/content/file.val.ts", schema, {
  // Only the path: the collection has the mimeType
  path: "/public/val/documents/report_a1b2c.pdf",
})