使用mongoose在mongodb中存储图像?如何? [英] store images in mongodb using mongoose?? how to?

查看:115
本文介绍了使用mongoose在mongodb中存储图像?如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都有一个快速的例子,使用mongoose和nodejs express



在mongodb中插入图像,我读了一些例子,但我不明白如何??



我想以表单上传图片

  app.post('/ video / new',function(req,res){
req.form.complete(function(err,fields,files){
console.log('here i go');
if(err){
next(err);
} else {
ins = fs.createReadStream(files.file.path);
console.log('insssssssssssss'+ ins);
ous = fs.createWriteStream(__ dirname +'/ static / uploads / videos /'+ files.file.filename);
util.pump(ins,ous,function(err){
if(err){
next(err);
} else {RegProvider.save({
file:req.param(files.file.filename),
filename:req.param('filename')
},function(error,docs){
res.redirect('/ video s');
});
}
});
//console.log('\\\
上载%s到%s',files.file.filename,files.file.path);
//res.send('Uploaded'+ files.file.filename +'to'+ files.file.path);
}
});
});

喜欢这个例子,但我不明白它是如何工作的

解决方案

util.pump 已弃用



您可以尝试 https://github.com/aheckmann/gridform https ://github.com/aheckmann/connect-multipart-gridform ,看看他们是否满足您的需求。


anybody has a quick example to insert an image in mongodb using mongoose and nodejs express

i read some examples but i cant understand how to??

i want to upload an image in a form

app.post('/videos/new', function(req, res) {
  req.form.complete(function(err, fields, files) {
    console.log('here i go');
    if(err) {
      next(err);
    } else {
      ins = fs.createReadStream(files.file.path);
      console.log('insssssssssssss'+ins);
      ous = fs.createWriteStream(__dirname + '/static/uploads/videos/' + files.file.filename);
      util.pump(ins, ous, function(err) {
        if(err) {
          next(err);
        } else { RegProvider.save({
           file: req.param(files.file.filename),
                   filename: req.param('filename')
                 }, function(error, docs) {
              res.redirect('/videos');
         });
        }
      });
      //console.log('\nUploaded %s to %s', files.file.filename, files.file.path);
      //res.send('Uploaded ' + files.file.filename + ' to ' + files.file.path);
    }
  });
});

like this example but i dont understand how it works

解决方案

util.pump is deprecated.

You might try out https://github.com/aheckmann/gridform or https://github.com/aheckmann/connect-multipart-gridform and see if they meet your needs.

这篇关于使用mongoose在mongodb中存储图像?如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆