var avatar = req.files.avatar; var avatar_filename = avatar.path.split(‘/’).pop(); easyimg.resize({ src: avatar.path, dst: __dirname + ‘/…/…/public/avatar_72/’ + avatar_filename, width: 72, height: 72, }, function(err, stdout, stderr) { if (err) throw err; easyimg.resize({ src: avatar.path, dst: __dirname + ‘/…/…/public/avatar_288/’ + avatar_filename, width: 288, height: 288, }, function(err, stdout, stderr) { User.findByIdAndUpdate(req.user.id, { avatar: avatar_filename }, function(err, user) { //remove tmp file and old image files fs.unlink(avatar.path, function(err) { console.log(err); }) if (‘no.jpg’ != req.user.avatar) { fs.unlink(__dirname + ‘/…/…/public/avatar_72/’ + req.user.avatar, function(err) { console.log(err); }); fs.unlink(__dirname + ‘/…/…/public/avatar_288/’ + req.user.avatar, function(err) { console.log(err); }); }; render_data.user = user; res.render('user/profile_avatar’, render_data); }); })
10 回复