Validators¶
FileSize
¶
Bases: Validator
Validator which succeeds if the file passed to it is within the specified
size range. If min
is not specified, or is specified as None
,
no lower bound exists. If max
is not specified, or is specified as None
,
no upper bound exists. The inclusivity of the bounds (if they exist) is configurable.
If min_inclusive
is not specified, or is specified as True
, then
the min
bound is included in the range. If max_inclusive
is not specified,
or is specified as True
, then the max
bound is included in the range.
Examples:
from apiflask import Schema
from apiflask.fields import File
from apiflask.validators import FileSize
class Image(Schema):
image = File(required=True, validate=FileSize(min='1 MiB', max='2 MiB'))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min |
Optional[str]
|
The minimum size (lower bound). If not provided, minimum size will not be checked. |
None
|
max |
Optional[str]
|
The maximum size (upper bound). If not provided, maximum size will not be checked. |
None
|
min_inclusive |
bool
|
Whether the |
True
|
max_inclusive |
bool
|
Whether the |
True
|
error |
Optional[str]
|
Error message to raise in case of a validation error.
Can be interpolated with |
None
|
Version added: 2.1.0
Source code in apiflask/validators.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
FileType
¶
Bases: Validator
Validator which succeeds if the uploaded file is allowed by a given list of extensions.
Examples:
from apiflask import Schema
from apiflask.fields import File
from apiflask.validators import FileType
class Image(Schema):
image = File(required=True, validate=FileType(['.png']))
Parameters:
Name | Type | Description | Default |
---|---|---|---|
accept |
Iterable[str]
|
A sequence of allowed extensions. |
required |
error |
Optional[str]
|
Error message to raise in case of a validation error.
Can be interpolated with |
None
|
Version added: 2.1.0
Source code in apiflask/validators.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
External documentation¶
Check out the Validator API documentation for the validators from marshmallow.