Search code examples
node.jspostmankoa

request.body is empty when trying to send an image to server NodeJS. The body is form-data type


request.body is empty when trying to send an image to server NodeJS. The body is form-data type. I am using koa-bodyparser. I want simple just to print on the console the request.body but is always undefined. Thank you for helping!


Solution

  • Problem Solved! Instead of using koa-bodyparser, i have used to following body parser:

       const bodyparser: any = require('koa-body');
       this.app.use(bodyparser({
                formidable:{
                    uploadDir: './uploads',
                    keepExtensions: true
                },
                multipart: true,
                strict: false, //allow application.json !
                urlencoded: true
            }));