Closed FWeinb closed 5 years ago
I agree 100%
What I did right now is use koa-compose
to combine the multer middlware and a simple middleware that copies ctx.req.files
, ctx.req.body
, & ctx.req.file
to ctx.request
. I know this is not the best way to do it but I can live with it until this is fixed.
Upload pictures are binary data, how can I convert the picture file?
@QianSu Did you try to change the file extension?
@dominhhai Brother, thank you for your advice, I have solved this problem
on my side, those below are always undefined
:
ctx.request.files
ctx.request.file
ctx.req.file
ctx.req.files
the configuration like this:
import multer from 'koa-multer'
import bodyparser from 'koa-bodyparser'
const upload = multer({ dest: '/path/to/tmp' })
//use it globally
app.use(multer.any())
app.use(bodyparser())
I tried postman and html form with enctype="multipart/form-data"
, both had saved file with hashed name but I can't access to file infomation via ctx
the version is koa-multer@1.0.1
and koa@2.2.0
.
Weired
Since pass ctx.req, ctx.next to an express middleware is kind of Hack. Why not delegate
ctx.req.body
/ ctx.req.file
/ ctx.req.files
to ctx.request
but not the reverse 😂
I have made a pull request that simply exposes the respective objects to Koa's Request wrapper. #15 Additionally updated the test requirements to node 6 or greater as Koa 2.x specifies as its requirement.
Side note: I have tried changing this middleware to pass the ctx.request object to multer, but that failed due to the fact that multer uses the streaming properties (eg: req.pipe(busboy)
) of the native Request object, whereas the Koa wrapper doesn't seem to have that exposed.
@fundon can be merge that pr?
Please see my comment at https://github.com/koa-modules/multer/issues/30#issuecomment-506837638 and close this issue. The official Koa organization has forked this repository and released it (with PR's merged) under @koajs/multer
. Thank you.
I think multer should write to
ctx.request
because that is the koa request object currently it is writing to thectx.req
which is the original node request object.In my opinion this change would align the behaviour of this module with the koa ecosystem.