如何使用gridfs-stream将图像上传到GridFS?

时间:2020-01-07 23:25:39

标签: node.js mongodb mongoose gridfs-stream

我有以下代码,其中我使用GridFS-stream将图像上传到名为“ test”的mongodb数据库中。

    const formidableMiddleware = require('express-formidable');
    var GridFS = Grid("test", mongoose.mongo);
    app.use(formidableMiddleware({multiples:true}));
    // for a driver/user to new a product
    app.post('/api/newRequest', (req, res) => {
        const form = new IncomingForm();

        const images = req.files.image;

        var writestream = GridFS.createWriteStream({
            filename: images[0].name
        });
        writestream.on('close', function (file) {
            console.log("WRITESTREAM CLOSED");
        });
      });

从客户端发送/ api / getRequest时,我在第var writestream...行收到以下错误:

[0] (node:15733) DeprecationWarning: GridStore is deprecated, and will be removed in a future version. Please use GridFSBucket instead
[0] TypeError: Cannot read property 'readPreference' of undefined

0 个答案:

没有答案