I've followed the express multipart example to upload a file to server, and it works fine. But if I use a route middleware like this (coffeescript):
loadUser = (req, res, next) ->
if req.session.user_id?
db.user.findById req.session.user_id, (err, user) ->
if user?
req.currentUser = user
next()
else
next()
else
next()
app.post '/file',loadUser, (req, res) ->
req.form.complete (err, fields, files) ->
if (err)
console.error err
else
console.log '\nuploaded %s to %s', files.image.filename, files.image.path
req.form.on 'progress', (bytesReceived, bytesExpected) ->
percent = (bytesReceived / bytesExpected * 100) | 0;
process.stdout.write 'Uploading: %' + percent + '\r'
The file doesn't upload and there's nothing log and no error. Then I clear the code in loadUser like this:
loadUser = (req, res, next) ->
next()
It works fine again. Is there something wrong in my loadUser method?