Spec-Zone.ru › Valibot

blob

Creates a blob schema.

The Blob class is not available by default in Node.js v16 and below.

const Schema = v.blob<TMessage>(message);

Generics

  • TMessage extends ErrorMessage<BlobIssue> | undefined

Parameters

  • message TMessage

Explanation

With blob you can validate the data type of the input. If the input is not a blob, you can use message to customize the error message.

Returns

  • Schema BlobSchema<TMessage>

Examples

The following examples show how blob can be used.

Image schema

Schema to validate an image.

const ImageSchema = v.pipe(
  v.blob('Please select an image file.'),
  v.mimeType(['image/jpeg', 'image/png'], 'Please select a JPEG or PNG file.'),
  v.maxSize(1024 * 1024 * 10, 'Please select a file smaller than 10 MB.')
);

Related

The following APIs can be combined with blob.

Schemas

array, exactOptional, intersect, lazy, looseObject, looseTuple, map, nonNullable, nonNullish, nonOptional, nullable, nullish, object, objectWithRest, optional, record, set, strictObject, strictTuple, tuple, tupleWithRest, undefinedable, union

Methods

assert, config, fallback, getDefault, getDefaults, getFallback, getFallbacks, is, message, parse, parser, pipe, safeParse, safeParser

Actions

check, brand, description, flavor, guard, maxSize, metadata, mimeType, minSize, notSize, rawCheck, rawTransform, readonly, size, title, transform

Utils

entriesFromList, isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/blob/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API