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, fn)
Validates all Buffer
values in a payload
given a whitelist
of file types provided in the options
.
Results in a joi-like ValidationError
if some file type is not allowed or unknown otherwise it returns the original parsed payload to account for additional custom validation.
Hapi
const Hapi = require('hapi');
const Houdin = require('houdin');
server = new Hapi.Server();
server.connection({
routes: {
validate: {
options: {
whitelist: ['png']
}
}
}
});
server.route({
config: {
validate: {
payload: Houdin.validate
},
payload: {
output: 'data',
parse: true
}
}
});
Standalone
const Houdin = require('houdin');
const options = { whitelist: ['png'] };
Houdin.validate({ file: new Buffer([0x89, 0x50]) }, options, (err, value) => {
console.log(err);
console.log(value);
});
Houdin.validate({ file: new Buffer([0x47, 0x49]) }, options, (err, value) => {
console.log(err);
console.log(value);
});
Supported File Types
The same as magik.