2

I have an http-triggered cloud function that works fine in the emulator but throws errors when deployed.

var multer  = require('multer');
var storage = multer.memoryStorage()
var multerUpload = multer({ storage: storage })


exports.selfie = function (req, res) {

  console.log ("START");
  console.log (req.body);

  // perf logging
  const startTime = process.hrtime();
  let markers = [];

  // data middleware
  let handle = multerUpload.single("image");
  handle(req, res, (err) => {
    console.log (">body");
    console.log (req.body);
    console.log (">file")
    console.log (req.file);
 })
}

In the emulator it acts as expected: The first console.log returns an empty object, the one after >body gives me all my POST variables, and the last a reference to uploaded image. It's being POSTed as a multipart form.

But when I deploy in prod the first console.log gives me a buffer, the second an empty object, and the file is undefined. POSTing the exact same data.

MNJam3
  • 23
  • 5
  • I've been scratching my head over the same question -- it looks like this is the same issue & solution: https://stackoverflow.com/questions/47242340/how-to-perform-an-http-file-upload-using-express-on-cloud-functions-for-firebase – Good Idea Mar 15 '18 at 04:45

0 Answers0