I am using NodeJS + Express. I submit a form, with a file to create an account. If I want to update that account, and don't want to update the image. Here is my code:
uploadAndSave: function (image, cb) {
if (!image) return this.save(cb)
var self = this
uploader.upload({'large': 300, 'small':150}, image,function(fileName){
self.logo.filename = fileName;
self.logo.cdnUri = 'https://myapp.s3.amazonaws.com/';
self.save(cb);
});
And in my controller:
exports.update = function(req, res){
var account = req.account
account = _.extend(account, req.body)
account.uploadAndSave(req.files.image, function(err) {
if (err) {
res.render('accounts/edit', {
title: 'Edit Account',
account: account,
errors: err.errors
})
}
else {
res.redirect('/accounts/' + account._id)
}
})
}
req.files.image is always have some value. I guess, after first file upload, this variable is set, and never removed. How can I remove it?