1
我正在使用NodeJS + Express。我提交一個表格,並用一個文件來創建一個帳戶。如果我想更新該帳戶,並且不想更新圖像。這裏是我的代碼:如何在NodeJS + Express應用程序中上傳文件後清除request.files?
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);
});
而且在我的控制器:
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總是有一定的價值。我想,在第一次上傳文件後,這個變量被設置,並且永遠不會被刪除。我怎樣才能刪除它?