expressjs / expressjs/multer

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

Open
#473 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
JavaScript
Stars
12.1k
Forks
1.1k
Avg merge
8d 2h
Merged PRs (30d)
21

Description

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);`

```javascript

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())
}
});
```
-------

```javascript

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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.