const functions = require('firebase-functions');const express = require('express');const Multer = require('multer');
const app = express();const multer = Multer();
const handleFieldsWithMulter = multer.fields([ { name: 'a_field' }, { name: 'another_field' }, { name: 'yet_another_field' }]);
const handlePostWithMulter = (req, res) => { const formData = req.body; res.status(200).send(formData);}
const loggingMiddleware = (req, res, next) => { console.log(`request body: ${req.body}`); next();}
app.post('/', loggingMiddleware, handleFieldsWithMulter, handlePostWithMulter);
const exchange = functions.https.onRequest(app)module.exports = { exchange}curl -X POST \ -F 'a_field=test' \ -F 'another_field=stuff' \ -F 'yet_another_field=things'request body: --------------------------a172e3b547372a6bContent-Disposition: form-data; name="a_field"
test--------------------------a172e3b547372a6bContent-Disposition: form-data; name="another_field"
stuff--------------------------a172e3b547372a6bContent-Disposition: form-data; name="yet_another_field"
things--------------------------a172e3b547372a6b--{"a_field":"test","another_field":"stuff","yet_another_field":"things"}
Cloud Functions provides request and response objects that are compatible with ExpressJS to make consuming HTTP requests simple. Cloud Functions automatically reads the request body, so you will always receive the body of a request independent of the content type. This means that HTTP requests should be considered to have been fully read by the time your code is executed. The nesting of ExpressJS apps should be used with this caveat—specifically, middleware that expects the body of a request to be unread may not behave as expected.
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/88848781-44eb-4aeb-8e00-16df8e38486c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/88848781-44eb-4aeb-8e00-16df8e38486c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/88848781-44eb-4aeb-8e00-16df8e38486c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.