Hi folks
Thanks for helping me out with my previous question about asynchronous
behaviour and callback!
Now I have a bit related issue, where I am stuck.
I have a user registration form wich works nicely. Now I am trying to
change that form to support user photo upload as well.
I am using Multer module and in the beginning everything worked fine.
*The problem comes when the user is not selecting any photo to be uploaded.*
I am saving the photos in a folder and storing to the DB (MySQL) all the
filenames. The problem is that I cant get the function *addUserToDB(req,
res) *called from a context where the file name is known. If the photo file
is given, I could call *addUserToDB* inside the callback
"onFileUploadComplete", however this never works if the photo file is not
given because there is not going to happen any file upload. On the other
hand, I could place this call inside "onParseEnd", which is always
executed, BUT I have no more access to the file name! I can't get the photo
name from res.body.filename anymore, its a different context :-(
Any hints how would you implement this would be a great help. Thanks in
advance.
var multer1 = multer({ dest: '../uploads/',
rename: function (fieldname, filename) {
return filename+Date.now();
},
onFileUploadStart: function (file) { },
onFileUploadComplete: function (file, req, res) {
done=true;
},
onParseEnd : function (req, next) {
// next();
}
});
router.post('/registerwithphoto', multer1, function(req, res) {
*addUserToDB(req, res)*
})
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/6cf6dbde-06ef-4ecf-bfc4-01e6578c755e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.