我的代码如下所示:
user.js的
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var user = new Schema({
login_type:Number, // 0 :facebook, 1: google
profile_img:String,
ph_no:Number,
user_name:String,
email_id:{type:String,required:true},
},{ versionKey: false });
module.exports = mongoose.model('user',user);
logtest.js
var userData = function(req, res) {
upload = multer({
limits: {
fileSize: 1000000,
files: 1
},
storage: storage,
fileFilter: function(req, file, callback) {
var ext = path.extname(file.originalname)
if (ext !== '.png' && ext !== '.jpg' && ext !== '.gif' && ext !== '.jpeg') {
return callback(res.end('Only images are allowed'), null)
}
callback(null, true);
}
}).single('profile_img');
upload(req, res, function(err) {
const user_name = req.body.user_name;
console.log("user name is "+ user_name);
.......
......
}
所以,这里发生的是,除了 user_name 之外的所有参数都来自请求,但有时候某种程度上未定义user_name。那么需要进行任何修改吗?