koa-body-images
v0.1.2
Published
Middleware to extract images from multipart/form-data uses koa-body
Downloads
4
Readme
koa-body-images
The middleware uses koa-body with option multipart: true
to extract images from ctx.body.files
. The images available like property of ctx.request.images
.
Installation
Install with npm
npm i koa-body-images
Usage with koa-body
const Koa = require('koa');
const Router = require('koa-router');
const koaBody = require('koa-body');
const koaBodyImages = require('koa-body-images');
const app = new Koa();
const router = new Router();
const options = {fromKeys: ["upload"], types: ["jpeg", "png"] multiples: true};
router.post('/', koaBodyImages(options), ctx => {
ctx.body = ctx.request.images;
});
app.use(koaBody({multipart: true}));
app.use(router.routes());
app.listen(3000);
Options
fromKeys
{Array} Array of strings. Extract images only from specified keys.multiples
{Boolean} If true, all values of keys will be wrapped into array. If false, the keys which have a several files will be ignored. Default: truetypes
{Array} Array of strings. Extract images only specified types. Extract images of any type by default. Available types:gif
jpeg
pjpeg
png
svg+xml
tiff
vnd.microsoft.icon
vnd.wap.wbmp
webp
x-icon
Nginx use this mime/type for .icox-jng
Nginx use this mime/type for .jngx-ms-bmp
Nginx use this mime/type for .bmp
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.