houdin
Route-level file type validation for hapi parsed in-memory multipart/form-data
request payloads. Also works as a standalone module.
Table of Contents
Installation
Install via NPM.
$ npm install houdin
Usage
validate(payload, options)
Validates all Buffer
values in a payload
given a whitelist
of file types provided in the options
. Throws a joi-like ValidationError
if some file type is not allowed or unknown otherwise it returns the original payload.
Hapi
const Hapi = ;const Houdin = ; const server = routes: validate: options: whitelist: 'image/png' ; server;
Standalone
const Houdin = ; const options = whitelist: 'image/png' ;const png = Buffer; const payload = Houdin; console; // { file: <Buffer 89 50 4e 47 0d 0a 1a 0a> }
const Houdin = ; const options = whitelist: 'image/png' ;const gif = Buffer; try Houdin;catch err console; // [ValidationError: child "file" fails because ["file" type is not allowed]]
Supported File Types
The same as file-type.