My code is as shown below:
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);
.......
......
}
So, here what happens is, all parameters except user_name are there from request, but somehow user_name is undefined sometimes. SO is there any modification required?
via M thaker
No comments:
Post a Comment