How do you handle optional file uploads with Sails JS?
<p>I have a form that a user can submit with or without a file.</p>

<p>The form:</p>

<pre><code>&lt;form method="post" action="/file/upload" enctype="multipart/form-data"&gt;
    &lt;input type="file" name="media" /&gt;
    &lt;input type="submit" value="Submit" /&gt;
&lt;/form&gt;
</code></pre>

<p>The Controller</p>

<pre><code>module.exports = {
  upload: function (req, res) {
    // Check if any files were uploaded
    if (!req.file('media')._files[0]) {
        return res.send('no file given!');
    }

    req.file('media').upload({
      dirname: '/tmp/uploads'
    },function whenDone(err, uploadedFiles) {
      if (err) {
        sails.log.error('Error uploading file', err);
      }
      res.send('thanks for your file');
    });
  }
};
</code></pre>

<p>If they don't upload a file, I get the following error. There doesn't seem to be a way to catch it or suppress it unless I go into the skipper code and comment out the error throwing. <strong>How can I submit the form without attaching a file and not crash the app?</strong></p>

<pre><code>Error: EMAXBUFFER: An Upstream (`NOOP_media`) timed out before it was plugged into a receiver. It was still unused after waiting 4500ms. You can configure this timeout by changing the `maxTimeToBuffer` option.
</code></pre>

<p>I've been through a number of forums and blog posts but nothing has helped so far.</p>