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?
File upload will always be fully completed once your route handler is invoked 馃憤
@LinusU would https://github.com/expressjs/multer/pull/399 change this?