expressjs / multer

Node.js middleware for handling `multipart/form-data`.
MIT License
11.46k stars 1.04k forks source link

Add configuration parameter to support Google Cloud Functions #1189

Open jacobg opened 1 year ago

jacobg commented 1 year ago

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.

TaherJerbi commented 9 months ago

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

IchordeDionysos commented 1 month ago

@LinusU @inigomarquinez this is blocking us and a lot of other people. Is this something you would be happy to support in Multer? 🤔

IchordeDionysos commented 1 month ago

There are even unmaintained forks of multer just to fix it for Cloud Functions: https://www.npmjs.com/package/multer-functions

inigomarquinez commented 3 weeks ago

I guess this is something for @expressjs/triagers to decide! 😀