Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jenyafross/koa-body-images
https://github.com/jenyafross/koa-body-images
images koa koa-body
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jenyafross/koa-body-images
- Owner: jenyafross
- License: mit
- Created: 2018-11-12T11:53:04.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-15T16:12:08.000Z (about 6 years ago)
- Last Synced: 2024-12-13T07:59:37.987Z (about 2 months ago)
- Topics: images, koa, koa-body
- Language: JavaScript
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-body-images [![Build Status](https://travis-ci.org/jenyafross/koa-body-images.svg?branch=master)](https://travis-ci.org/jenyafross/koa-body-images)
The middleware uses [koa-body](https://github.com/dlau/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
```bash
npm i koa-body-images
```## Usage with koa-body
```nodejs
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: true__
* `types` **{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 .ico
* `x-jng` Nginx use this mime/type for .jng
* `x-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.
## License
[MIT](https://choosealicense.com/licenses/mit/)