$ npm i egg-multer --save
// {app_root}/config/plugin.js
exports.multer = {
enable: true,
package: 'egg-multer',
}
// {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.
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 }
}
Please open an issue here.