Validate files based on their mime type.

When using defineFilePond the value of the accept attribute on the <input type="file"> is automatically passed to this extension.

import { defineFilePond } from 'filepond';
import { locale } from 'filepond/locales/en-gb.js';
import { FileMimeTypeValidator } from 'filepond/extensions/file-mime-type-validator.js';

defineFilePond({
    locale,
    extensions: [
        // Add the FileMimeTypeValidator extension
        [FileMimeTypeValidator, {
            accept: ['image/jpeg', 'image/png']
        }]
    ]
})

Configuration

The FileMimeTypeValidator extension accepts an option object of type FileMimeTypeValidatorOptions which defines the properties below.

accept

An array of accepted file mime types, also accepts the wildcard character for example ['image/*']

accept?: string | (string | RegExp)[]

format

Formats the mime types for presentation in a validation message. By default will use the uppercased last part of the mime types joined with ‘,’

format?: (mimeTypes: string[]) => string