koajs / koa-body

koa body parser middleware
MIT License
950 stars 130 forks source link

Multipart and JSON body #164

Open NelsonFrancisco opened 5 years ago

NelsonFrancisco commented 5 years ago

Problem/Feature Request Summary

Multipart form and json body in the same request

Environment Information

Current Behavior

Request pends forever

Steps to Reproduce

  1. Use koa body with
    {
    multipart: true,
    json: true,
    formidable: {
      hash: 'sha1',
      uploadDir,
      multiple: false,
      keepExtensions: true,
      maxFileSize: maxFileSize * 1024 * 1024,
    },
    }
  2. use superagent and send a request
    agent
    .patch(`/whatever`)
    .send({
        name: 'John Doe',
    })

Expected Behavior

It should parse json body correctly.

Context (Environment)

I'm trying to provide an API PATCH route that allows both multipart form(for uploading images) and json body, to change the properties on a database entity.

NelsonFrancisco commented 5 years ago

Ignore this. I was registering koa-body middleware two times in the route I was testing. Apparently, registering first with json:true and the second time with json:true and multipart: true makes koa-body never to resolve bodyPromise

NelsonFrancisco commented 5 years ago

So, I still didn't revolve my issue. Is koa-body middleware compatible with two instances in the same route? Because I want to make an API in which I have some routes that allow multipart, and others that don't.