在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:koajs/multer开源软件地址:https://github.com/koajs/multer开源编程语言:JavaScript 100.0%开源软件介绍:@koa/multer
Call for MaintainersThis module is a fork of koa-multer, the most widely used multer middleware in the koa community. Due to lack of maintenance, it was forked to the official Koa organization and is available under Install
npm install --save @koa/multer multer Usageconst Koa = require('koa');
const Router = require('@koa/router');
const multer = require('@koa/multer');
const app = new Koa();
const router = new Router();
const upload = multer(); // note you can pass `multer` options here
// add a route for uploading multiple files
router.post(
'/upload-multiple-files',
upload.fields([
{
name: 'avatar',
maxCount: 1
},
{
name: 'boop',
maxCount: 2
}
]),
ctx => {
console.log('ctx.request.files', ctx.request.files);
console.log('ctx.files', ctx.files);
console.log('ctx.request.body', ctx.request.body);
ctx.body = 'done';
}
);
// add a route for uploading single files
router.post(
'/upload-single-file',
upload.single('avatar'),
ctx => {
console.log('ctx.request.file', ctx.request.file);
console.log('ctx.file', ctx.file);
console.log('ctx.request.body', ctx.request.body);
ctx.body = 'done';
}
);
// add the router to our app
app.use(router.routes());
app.use(router.allowedMethods());
// start the server
app.listen(3000); Contributors
LicenseMIT © Fangdun Cai |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论