GridFsStorage未存储到数据库中

时间:2019-02-25 15:27:38

标签: node.js mongodb

这是我的代码。当我单击成功提交按钮时,将显示闪存消息,但数据未存储到数据库中。我已经为衣服创建了GridFsStorage。两者都在同一页面上。第一个工作正常。___________________________________________________________________________________________________________________________________________________________________________

   const Mongo = 'mongodb://localhost/milenz';

  // Create Storage engine - Shoe
   var storage_shoe = new GridFsStorage({
   url: Mongo,
   file: (req, file) => {
   return new Promise((resolve, reject) => {
   crypto.randomBytes(16, (err, buff) => {
    if (err) {
      return reject(err);
    }
    const shoename = buff.toString('hex') + path.extname(file.originalname);
    const fileInfo_shoe = {
      filename: shoename,
      bucketName: 'shoe',
      metadata: {
      'brand': req.body.shoe_brand,
      'type': req.body.shoe_type,
      'name': req.body.shoe_name,
      'color': req.body.shoe_color,
      'price': req.body.shoe_price,
      'info': req.body.shoe_info,
      'dis': req.body.shoe_discount
      }
  };
    resolve(fileInfo_shoe);
  });
 });
}
});
   const upload_shoe = multer({ storage_shoe });

   // Upload Women Shoe Image To DB
    router.post('/shoe', upload_shoe.single('shoe_pic'), (req,res)=> {
    req.flash('success_msg','Shoe is successfully stored');
    res.redirect('/admin/shoe');
  });

0 个答案:

没有答案