Multer: Question - sync order guaranteed for upload and then callback? or is it async?

Created on 5 Apr 2017  路  2Comments  路  Source: expressjs/multer

I see that behavior is process/upload file first upload.array('listingImage', 5), and then run route callback apiLogic.updateListing in:

api.route('/listings/:listingID').post(upload.array('listingImage', 5), apiLogic.updateListing);


var storage = multer.diskStorage({
  destination: function (req, file, cb) {
    var path = `listing-pics/${req.body.internalUserID}`;
    mkdirp.sync(path, { opts: { mode: 0755 } } );
    cb(null, path)
  },
  filename: function (req, file, cb) {
    console.log('first');
    cb(null, file.fieldname + '-' + Date.now())
  }
});


function updateListing(req, res) {
  var id = req.params.listingID;

  console.log('second');

   // HERE I WILL DO IMAGE MAGIC MODIFICATIONS AFTER 
   // FILE IS UPLOADED
  res.status(200).end();
}

My quesiton is, is this synchronous behavior guaranteed where file upload happens first and route callback apiLogic.updateListing runs afterwards? Or am I just working off a async race condition that could change?

question

All 2 comments

File upload will always be fully completed once your route handler is invoked 馃憤

Was this page helpful?
0 / 5 - 0 ratings