Code Monkey home page Code Monkey logo

Comments (9)

raphaelsoul avatar raphaelsoul commented on August 26, 2024 7

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 [email protected] and [email protected].

Weired

from multer.

i5ting avatar i5ting commented on August 26, 2024 6

@fundon can be merge that pr?

from multer.

danegigi avatar danegigi commented on August 26, 2024 5

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.

from multer.

techanon avatar techanon commented on August 26, 2024 1

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.

from multer.

QianSu avatar QianSu commented on August 26, 2024

Upload pictures are binary data, how can I convert the picture file?

from multer.

dominhhai avatar dominhhai commented on August 26, 2024

@QianSu Did you try to change the file extension?

from multer.

QianSu avatar QianSu commented on August 26, 2024

@dominhhai Brother, thank you for your advice, I have solved this problem

from multer.

magicdawn avatar magicdawn commented on August 26, 2024

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 😂

from multer.

niftylettuce avatar niftylettuce commented on August 26, 2024

Please see my comment at #30 (comment) and close this issue. The official Koa organization has forked this repository and released it (with PR's merged) under @koajs/multer. Thank you.

from multer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.