multer icon indicating copy to clipboard operation
multer copied to clipboard

Add configuration parameter to support Google Cloud Functions

Open jacobg opened this issue 1 year ago • 1 comments

Multer calls req.pipe(busboy) to stream in the request body for processing: https://github.com/expressjs/multer/blob/07c9e84477e19f6f5016330b0c37c7cfbf085b8d/lib/make-middleware.js#L177

However, on Google Cloud Functions (GCF), it wraps Express to pre-stream the entire request body into a custom res.rawBody property. This causes Multer to break on that runtime. Here is some background discussion: https://stackoverflow.com/a/47319614/1237919

It would be a very simple solution to instead call the following when running on GCF:

busboy.end(req.rawBody)

This could be supported by either:

  1. adding a configuration parameter specifically for GCF.
  2. adding a configuration parameter function to override the reading in of data however the caller wants.

I would be happy to submit a pull request for this. Would you be willing to accept it? Do you prefer one of these 2 options?

Thanks.

jacobg avatar Feb 28 '23 13:02 jacobg

I believe this would solve #1144 for people trying to use multer on cloud functions.

TaherJerbi avatar Sep 19 '23 09:09 TaherJerbi