I'm trying to upload a file using @koa/multer and js according to the library documentation, but it only works on GET endpoints and if I try to replicate the same thing in POST enpoints the file property is undefined. Does anyone know how to fix it?
ROUTER.js
import Router from 'koa-router';
import Multer from '@koa/multer';
const router = new Router();
const upload = multer();
router.post('/test', upload.single('csv'), Controller.test) //if change to GET works fine!!
module.exports = router;
CONTROLLER.js
async test(ctx) {
console.log(ctx.request.file); //undefined
console.log(ctx.file); //undefined
console.log(ctx.request.body); //undefined
ctx.response.status = 204;
}
if router is get the console.logs return
{
fieldname: 'csv',
originalname: 'namefile.csv',
encoding: '7bit',
mimetype: 'text/csv',
buffer: <Buffer 41 63 63 65 73 43 55 4d 51 45 53 4b 53 47 51 4b 45 ... 46 more bytes>,
size: 96
}