Multer: Initializing multer without it being in the argument? (Google Cloud Functions)

Created on 15 Mar 2017  路  4Comments  路  Source: expressjs/multer

Trying to use google cloud functions, which requires functions to be exported, without access to the app class (like so)...

exports.helloWorld = (req, res)=>{
}

I'm wondering how to initialize multer within a function like above, since multer is traditionally implemented in the argument class like below...

app.post('/', multer().single(...), function (req, res) {
})

Anyone have any ideas? Sorry if the question is confusing/vague, and feel free to ask me to clarify anything

Most helpful comment

const parseBody = multer().single(...)
exports.helloWorld = (req, res, next) => {
  parseBody(req, res, function (err) {
    if (err) return next(err)

    // use `req.file` here
  })
}

All 4 comments

const parseBody = multer().single(...)
exports.helloWorld = (req, res, next) => {
  parseBody(req, res, function (err) {
    if (err) return next(err)

    // use `req.file` here
  })
}

@LinusU Unfortunately, calling it that way produces a TypeError: Cannot read property 'transfer-encoding' of undefined error.

Similar to issue #167 where it's caused by calling multer incorrectly

hehe, sorry, I had a typo :)

I've edited the post

Ah, it's working now. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arsinawaz picture arsinawaz  路  4Comments

bpetty-formfast picture bpetty-formfast  路  3Comments

samipjain picture samipjain  路  4Comments

BlueOctober picture BlueOctober  路  3Comments

ChristianRich picture ChristianRich  路  4Comments