title: Cloud Functions for Firebase Endpoint to Process an Image
body: <p>I want to create a cloud function endpoint that can accept and process image files such as JPEG.  This is my code:</p>
  
  <pre><code>var express = require('express')
  var multer  = require('multer')
  //firebase complains that '/user_code/tmp' is read-only if I use this
  //var upload = multer({ dest: 'tmp/' })
  var upload = multer({
    storage: multer.MemoryStorage,
    fileSize: 5 * 1024 * 1024
  });
  var app = express()
  
  app.post('/image-upload', upload.single('image'), function(req, res, next) {
  
     console.log("request data: " + JSON.stringify(req.data));
     console.log("request params: " + JSON.stringify(req.params));
     console.log("request query: " + JSON.stringify(req.query));
     console.log("request body: " + JSON.stringify(req.body));
     console.log("request headers: " + JSON.stringify(req.headers));
     console.log("req.file: " + req.file);
     console.log("req.files: " + req.files);
  
     res.status(201).send(`My Server Response is ${req.file}`);
  });
  
  module.exports.testEndpoint = functions.https.onRequest(app);
  </code></pre>
  
  <p>For some reason, req.file and req.files is always <code>undefined</code>.  However, req.body does appear to contain my image.  I am using Postman to send the HTTP POST request.</p>
  
  <p><a href="https://i.stack.imgur.com/WLpEK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WLpEK.png" alt="Postman Input and Response"></a></p>