title: Node.js Multer Filename
body: <p>I want to customizes the filename of my app by the value of an input instead of the fieldname. <br>In the other words, I want to change the <em>file.filename</em> by one thing like <em>req.body.my_field</em> were my_field is the name of an input. <br>Finally, I want something like this:   </p>
  
  <pre><code>"filename": "value_of_my_field-1530606094020.jpg",  
  "path": "uploads\\value_of_my_field-1530606094020.jpg",  
  </code></pre>
  
  <p>Noticed that the value of my_field appear on my console.<br>
  I need some help to do this.<br>
   Here's my code:</p>
  
  <pre><code>var express = require('express')
  var multer  = require('multer')
  const path = require('path')
  
  // Init app
  var app = express()
  const port= 3000
  
  // Set storage engine
  const storage = multer.diskStorage({
      destination: './uploads/',
      filename: function(req, file, cb){
          cb(null, file.fieldname + '-' + Date.now() +     path.extname(file.originalname));
      }
  });
  
  // Init upload
  const upload = multer({
      storage: storage,
      limits:{fileSize:1000000},
  });
  
  
  app.post('/upload', upload.single('myImage'), function (req, res, next) {
      if(req.file == undefined){
          res.json({'Error': 'No File Selected!'});
      } else {
          res.json(req.file);
          console.log(req.body.my_field);
      }
  })
  
  app.listen(port, () =&gt; console.log('server started on port '+ port));
  </code></pre>
  
  <p>Thanks in advance</p>