新手请教关于图片上传问题 500 TypeError
发布于 1年前 作者 drug7023 572 次浏览

提示错误:500 TypeError: Cannot read property ‘upload’ of undefined 应该是很白痴的问题…但是我发现不了…求各位大神救援!

app.get('/post', function(req, res){ 

res.render('post', {

title: '发表',

user: req.session.user,

success: req.flash('success').toString(),

error: req.flash('error').toString()

  });

});

//post '/post'

app.post('/post', checkLogin);

app.post('/post', function(req, res){

var currentUser = req.session.user;

   var tmp_path = req.files.upload.path;

   console.log("temp_path->"+tmp_path);
    
   var target_path = './public/images/' + req.files.upload.name;

fs.rename(tmp_path, target_path, function(err) {

    if (err) throw err;

    fs.unlink(tmp_path, function() {

        if (err) throw err;

        res.send('File uploaded to: ' + target_path + ' - ' + req.files.upload.size + ' bytes' + "target_path" + target_path);

    });

});

 post.save(function (err){

  if (err){

   req.flash('error', err);

   return res.redirect('/');

  }
    
  req.flash('success', '发布成功!');

  res.redirect('/');

 });
})
1 回复
app.use(express.bodyParser()); // use it

签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

回到顶部