tunnckoCore / opensource

Delivering delightful digital solutions. Monorepo of monorepos of Open Source packages with combined ~100M/month downloads, semantically versioned following @conventional-commits. Fully powered ES Modules, @Airbnb @ESLint + @Prettier, independent & fixed versioning. Quality with @Actions, CodeQL, & Dependabot.
https://tunnckocore.com/opensource
480 stars 18 forks source link

Can't make the multipart work with koa-router #41

Open vhpoet opened 7 years ago

vhpoet commented 7 years ago

I'm on koa@2.2.0, koa-router@7.2.0 and koa-better-body@3.0.2.

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 commented 7 years ago

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

tunnckoCore commented 7 years ago

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.

imkimchi commented 7 years ago

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