opensource icon indicating copy to clipboard operation
opensource copied to clipboard

Can't make the multipart work with koa-router

Open vhpoet opened this issue 7 years ago • 3 comments

I'm on [email protected], [email protected] and [email protected].

Trying to disable multipart for all the routes except /profilepic.

app.use(body({
  multipart: false,
  strict: false
}))
router.post('/profilepic',
  body({
    multipart: true,
    uploadDir: path.resolve(__dirname, '../../../uploads')
  }),
  this.changeProfilePicture
)

with this code changeProfilePicture is never called. It works if I remove the body() from the router and use multipart: true on app.use.

vhpoet avatar May 31 '17 17:05 vhpoet

actually even router.post('/profilepic', body(), this.changeProfilePicture) doesn't work, with or wihtout app.use(body()).

vhpoet avatar May 31 '17 17:05 vhpoet

Hmm.. strange, don't know. Can you please try koa-better-router? It's almost the same (and even more better) and is guaranteed to work with this version of koa-better-body.

It was working, probably some new versions of koa-router do something, i don't following it.

tunnckoCore avatar May 31 '17 21:05 tunnckoCore

you don't have to disable multipart because this module doesn't provide ctx.request.fields only when the request is multipart/form-data. so you could just parse body without handling multipart

imkimchi avatar Jul 18 '17 14:07 imkimchi