• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

dominhhai/koa-busboy: Upload files with Busboy

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

dominhhai/koa-busboy

开源软件地址:

https://github.com/dominhhai/koa-busboy

开源编程语言:

JavaScript 100.0%

开源软件介绍:

koa-busboy

A koa's middleware for handling multipart form. Note that, this middleware supports Koa v2 only.

Installation

$ npm i -S koa-busboy

Usage

koa-busboy will adds all text fields to ctx.request.body object and uploaded files to ctx.request.files array.

To create middleware, simply call the module function with custom config options as following:

const busboy = require('koa-busboy')
const uploader = busboy(options)

While, options is same as original busboy module.

However, you can specify the following options also.

  • dest - string - The folder to save uploaded files (Default: system temp folder - os.tmpdir()).

  • fnDestFilename - function - The function that defines the final filename which saved on dest folder. The fnDestFilename(fieldname, filename) function will return the name of file which be saved on disk. While fieldname is your uploaded field's name and filename is your uploaded file's name. (Default: (fieldname, filename) => Date.now() + fieldname + filename)

Example

const busboy = require('koa-busboy')
const koaRouter = require('koa-router')

const uploader = busboy({
  dest: './upload' // default is system temp folder (`os.tmpdir()`)
  fnDestFilename: (fieldname, filename) => uuid() + filename
})
const router = koaRouter()

router.post('/upload', uploader, async ctx => {
  // fields
  // text fields is add to ctx.request.body object
  let { name } = ctx.request.body
  // files
  // uploaded files is add to ctx.request.files array
  let fileReadStream = ctx.request.files[0]
})



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Lobos/qenya: mock server base on koa and react发布时间:2022-07-09
下一篇:
w3cways/koa-api: koa2中文文档发布时间:2022-07-09
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap