Skip to content

elixiao/egg-multer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

egg-multer

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-multer --save

Usage

// {app_root}/config/plugin.js
exports.multer = {
  enable: true,
  package: 'egg-multer',
}

Configuration

// {app_root}/config/config.default.js

// Accept a single file with the name `uri`
exports.multer = {
  single: 'uri', 
}

// Accept an array of files, all with the name `files`
exports.multer = {
  array: 'files', 
}

// Accept a mix of files, specified by fields
exports.multer = {
  fields: [{name: 'file', maxCount: 1}],
}

// Accept only text fields
exports.multer = {
  none: true,
}

// Accepts all files that comes over the wire
exports.multer = {
  any: true,
}

see config/config.default.js for more detail.

Example

async multer() {
  const { ctx, app } = this
  console.log('is multipart', ctx.is('multipart'))
  console.log('is json', ctx.is('json'))
  console.log('request.body', ctx.request.body)
  console.log('ctx.file', ctx.file)
  console.log('ctx.files', ctx.files)
  ctx.body = { ok: 1 }
}

Questions & Suggestions

Please open an issue here.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published