Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhike-team/koa2-upload
A middleware for koa2 to handle multipart request based on formidable
https://github.com/zhike-team/koa2-upload
Last synced: 21 days ago
JSON representation
A middleware for koa2 to handle multipart request based on formidable
- Host: GitHub
- URL: https://github.com/zhike-team/koa2-upload
- Owner: zhike-team
- License: mit
- Created: 2018-05-29T12:12:16.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-25T01:44:24.000Z (almost 2 years ago)
- Last Synced: 2024-04-29T01:41:10.571Z (9 months ago)
- Language: JavaScript
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# koa2-upload
基于formidable的,适用于koa2的处理文件上传的中间件
## 安装
```sh
npm i --save @zhike/koa2-upload
```## 使用方法
```javascript
const koa = require('koa');
const app = new Koa();const fileHandler = require('koa2-upload');
app.use(fileHandler({ autoDelete: true }))
app.use(async (ctx)=>{
// ctx.fields
// ctx.files})
```### Options
* stream: 默认值 false , 设置为true会将上传文件流挂载在ctx.files[key].stream中
* autoDelete: 默认值 false ,设置为true在请求结束之后会删除本地缓存文件* uploadDir: 设置为文件保存路径
* maxFileSize: 设置上传文件最大字节数