title: Multer 'storage' option does not work while 'dest' one does
body: <p>I'm using Multer to upload and store files. If I use the <code>dest</code> option files upload to my <code>/uploads</code> folder with no problem. Whilst this works, it's saving the uploads like <code>2eb3f1a6def453f7a461c5de353b06f8</code> so I want to use the <code>storage</code> option, but for some reason this doesn't work or me and the files upload (logged in console), but wont save to the folder.</p>
  <p>I've tried a few different ways of achieving this and none work. Can anyone point out what might be wrong?</p>
  <pre><code>{
      fieldname: 'attachments',
      originalname: 'myFile.pdf',
      encoding: '7bit',
      mimetype: 'application/pdf',
      destination: 'uploads/',
      filename: '2eb3f1a6def453f7a461c5de353b06f8',
      path: 'uploads/2eb3f1a6def453f7a461c5de353b06f8',
      size: 57638
    }
  </code></pre>
  <pre><code>const express = require('express');
  const app = express();
  const multer = require(&quot;multer&quot;);
  const path = require('path');
  // const upload = multer({ dest: &quot;uploads/&quot; }); // this works, file saves to /uploads
  var upload = multer({ storage: storage }); // this doesnt work/ files dont save to /uploads
  // Parse URL-encoded bodies (as sent by HTML forms)
  app.use(express.urlencoded());
  // Parse JSON bodies (as sent by API clients)
  app.use(express.json());
  
  var storage = multer.diskStorage({
    destination: function(req, file, cb) {
      // cb(null, 'uploads/');
      // cb(null, __dirname + '/uploads');
      cb(null, './uploads');
     },
    filename: function (req, file, cb) {
      // cb(null , file.originalname);
      // cb(null, file.fieldname + '-' + Date.now());
  
      // By default, multer removes file extensions so let's add them back
      cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
    }
  });
  
  // var upload = multer({ storage: storage });
  
  app.post('/', upload.array('attachments') , (req, res) =&gt;{
    try {
      res.send(req.files);
      console.log('body', req.body);
      console.log('files', req.files);
    } catch(error) {
      console.log(error);
      res.send(400);
    }
  });
  
  
  module.exports = {
    path: '/api/upload',
    handler: app
  };
  
  </code></pre>