@vinejs/vine - v4.2.0
    Preparing search index...

    Class VineNativeFile

    VineNativeFile represents a platform native File class instance. This type is used to validate file uploads in browser environments where the File API is available.

    The file is validated based on type, size, and MIME type constraints. Unlike MultipartFile (used in Node.js), this works with the browser's native File object from file input elements.

    const schema = vine.object({
    avatar: vine.file().maxSize('2mb').mimeTypes(['image/jpeg', 'image/png']),
    document: vine.file().minSize('1kb').maxSize('10mb')
    })
    // From HTML file input
    // <input type="file" name="avatar" />
    const file = event.target.files[0] // This is a native File instance

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    "[ITYPE]": File

    Define the input type of the schema for TypeScript inference

    "[OTYPE]": File

    The output value type of the field after validation. The property points to a type only and not the real value.

    "[COTYPE]": File

    Type marker for camelCase output type inference

    dataTypeValidator?: Validation<any>

    The validation to use for validating the schema data type. Using a data type validator guards custom rules to only run when the data type validation passes.

    class StringSchema extends BaseLiteralType {
    dataTypeValidator = stringDataTypeRule
    }
    options: FieldOptions

    Configuration options for this field including bail mode, nullability, and parsing

    rules: {
        maxSize: (
            ...options: [options: { max: number }],
        ) => Validation<{ max: number }>;
        mimeTypes: (
            ...options: [options: { mimeTypes: string[] }],
        ) => Validation<{ mimeTypes: string[] }>;
        minSize: (
            ...options: [options: { min: number }],
        ) => Validation<{ min: number }>;
    } = ...

    Static collection of all available validation rules for native files

    "[SUBTYPE]": string = 'nativeFile'

    The subtype identifier for the literal schema field

    "[UNIQUE_NAME]": string = 'vine.nativeFile'

    Unique name identifier for union type resolution

    Methods

    • Define a method to parse the input value. The method is invoked before any validation and hence you must perform type-checking to know the value you are working it.

      Parameters

      • callback: ParseFn

      Returns this

    • Adds a validation rule to the schema's validation chain. Rules are executed in the order they are added.

      Parameters

      Returns this

      This schema instance for method chaining

      vine.string().use(minLength({ length: 3 }))
      vine.number().use(customRule({ strict: true }))
    • Enable/disable bail mode for this field. In bail mode, field validations stop after the first error.

      Parameters

      • state: boolean

        Whether to enable bail mode

      Returns VineNativeFile

      This schema instance for method chaining

      vine.string().bail(false) // Continue validation after first error
      vine.number().bail(true) // Stop after first error (default)
    • Compiles the literal schema type into a compiler node. This method transforms the schema definition into a format that the validation compiler can process.

      Parameters

      • propertyName: string

        Name of the property being compiled

      • refs: RefsStore

        Reference store for the compiler

      • options: ParserOptions

        Parser options including camelCase conversion

      Returns FieldNode & {} & { subtype: string }

      Compiled literal node with subtype information

    • Type checker function to determine if a value is a native file. Required for "unionOfTypes" functionality.

      Parameters

      • value: unknown

        The value to check

      Returns value is File

    • Enforce the file type to be one of the specified MIME types.

      Parameters

      • types: string[]

        Array of allowed MIME types

      Returns VineNativeFile

      vine.file().mimeTypes(['image/jpeg', 'image/png', 'image/gif'])
      
      vine.file().mimeTypes(['application/pdf'])