title: Receiving Multi-Part Form Data with Meteor + Multer?
body: <p>I have <code>express</code>-oriented sample code for receiving multi-part form data from a provider:</p>
  
  <pre><code>const multer = require('multer');
  const callback = multer();
  
  app.post('/callback', callback.single('json'), (req, res) =&gt; {
    res.status(200);
    res.send('API Event Received');
  
    const data = req.body.json;
    const events = JSON.parse(data);
    const eventType = events.event.event_type;
    const signatureRequestId = events.signature_request.signature_request_id;
  
    switch(eventType) {
      case 'signature_request_sent':
        console.log(`Signature request ${signatureRequestId} has been sent.`);
        break;
      case 'signature_request_viewed':
        console.log(`Signature request ${signatureRequestId} has been viewed.`);
        break;
      case 'signature_request_downloadable':
        console.log(`Signature request ${signatureRequestId} is downloadable.`);
        break;
      case 'signature_request_signed':
        console.log(`Signature request ${signatureRequestId} has been signed.`);
        break;
      case 'signature_request_declined':
        console.log(`Signature request ${signatureRequestId} has been declined.`);
        break;
      default:
        console.log('');
        break;
    }
  
  });
  </code></pre>
  
  <p>On <a href="https://stackoverflow.com/questions/30714445/how-to-properly-configure-meteor-to-work-with-node-file-uploading-module-multer">this SO post,</a> I saw an example of connecting Meteor to Multer for purposes of receiving image files:</p>
  
  <pre><code>if (Meteor.isServer) {
    Meteor.startup(function () {
      multer({ dest: './uploads/',
          rename: function (fieldname, filename) {
              return filename+Date.now();
          },
          onFileUploadStart: function (file) {
              console.log(file.originalname + ' is starting ...');
          },
          onFileUploadComplete: function (file) {
              console.log(file.fieldname + ' uploaded to  ' + file.path);
              var fileName = file.name;
              var done=true;
          }
      })
    });
  }
  </code></pre>
  
  <p>...but I haven't figured out yet how to combine the two code samples. </p>
  
  <p>What's the correct way to use Multer in Meteor to receive multi-part form data?</p>
  
  <p><strong>UPDATE:</strong> A commenter asked what I had tried so far. I have this Meteor code that creates regular, single-part REST endpoint:</p>
  
  <pre><code>WebApp.connectHandlers.use('/ReceiveCalls', (req, res, next) =&gt; {
      console.log('received message');
      console.log( req);
      console.log(res);
      res.writeHead(200);
  });
  </code></pre>
  
  <p>The Multer sample show above, includes a destination folder to receive images, but it doesn't show how to create the endpoint.  The Meteor code shows how to create a REST endpoint, but I can't yet see how to combine it with the Multer code. I'm sure it's pretty easy, but I haven't yet figured out how to do it.</p>