使用mongoose在mongodb中存储图像?如何?

时间:2020-12-16 02:33:58

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

任何人都有一个快速的例子,使用mongoose和nodejs express在mongodb中插入图像

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

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

1 个解决方案

#1


5  

util.pump is deprecated.

util.pump已弃用。

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

您可以尝试https://github.com/aheckmann/gridform或https://github.com/aheckmann/connect-multipart-gridform,看看它们是否符合您的需求。

#1


5  

util.pump is deprecated.

util.pump已弃用。

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

您可以尝试https://github.com/aheckmann/gridform或https://github.com/aheckmann/connect-multipart-gridform,看看它们是否符合您的需求。