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');
const server = new Hapi.Server();
server.connection({
routes: {
validate: {
options: {
whitelist: ['image/png']
}
}
}
});
server.route({
config: {
validate: {
payload: Houdin.validate
},
payload: {
output: 'data',
parse: true
}
}
});
Standalone
const Houdin = require('houdin');
const options = { whitelist: ['image/png'] };
const png = Buffer.from('89504e47', 'hex');
Houdin.validate({ file: png }, options, (err, value) => {
console.log(err);
console.log(value);
});
const Houdin = require('houdin');
const options = { whitelist: ['image/png'] };
const gif = Buffer.from('47494638', 'hex');
Houdin.validate({ file: gif }, options, (err, value) => {
console.log(err);
console.log(value);
});
Supported File Types
The same as file-type.