Open supermacro opened 7 years ago
This is a duplicate of #161, but provides further info.
Have you been able to work around the issue? I've run into the same thing (using a similar setup) and can't get a function that works 100% in the emulator to work after deployment which is very frustrating.
@n0wak Our team decided it wasn't worth the hassle. Not sure why google thought it was a good idea to parse the body of a request (as though us node devs didn't know how to do that ourselves) before turning over control of the request to the cloud function.
We just spun up a compute instance. IMO functions as a service come with a lot of complications and it's not worth it other than to save a substantial amount of money when running a large scale operation.
fwiw, I got around this by following G. Rodriguez's instructions here: https://stackoverflow.com/a/47603055
This SHOULD be properly documented + commited to the local emulator. Took me a few days to get around this. It's a shame I didn't see this issue until now.
Environment details
Steps to reproduce
Notes
I am sending
PUT
requests withContent-Type
set tomultipart/form-data
to have the cloud function process files and then upload them to google cloud storage.I am using multer to parse the request and provide a
.files
object onreq
.req.files
is an object whose keys are the various form keys.Local Behaviour
The cloud function works as intended.
req.files
is populated with an object that I then process and stream its contents to google cloud storate.However,
req.rawBody
does not exist (not that it's an issue in this case).Remote behavior
The cloud function does not work as intended.
req.files
is not populated with any data (in this case, it is an empty object) and the server crashes.In the remote case,
req.rawBody
is indeed a node Buffer object as the documentation states.Conclusion
I guess there are two takeaways:
1 - rawBody should exist in local development to better mirror the true behavior of hosted cloud functions
2 - multer should work remotely assuming that
req
isn't being mutated to such a point as to prevent multer from doing its job of parsing multipart requests. I know this might be out of scope from this repo but it is still something to be aware of. From my understanding, all npm modules should work with GCF.