小编Ana*_*and的帖子

错误:grid.mongo.GridStore不是构造函数,使用mongoose、Grid-fs-stream和grid multer存储

我收到以下提到的错误。基本配置如下: 我已将文件上传到服务器上,我想下载它们,但收到这些错误时,我向 /api/files/delete/${fileId} 调用了 POST 请求,该请求应该调用路由并返回文件发送到浏览器,而不是使用网格相关模块获取错误。

MONGODB_CONNECTION_STRING = mongodb://localhost:27017/Cstore

Db structure={Cstore:{uploads.files,uploads.chunks,users}}

On requesting POST         axios.post(`/api/files/delete/${fileId}`)

Getting error: 

     this._store = new grid.mongo.GridStore(grid.db, this.id || new grid.mongo.ObjectID(), this.name, this.mode, options);
[0]                 ^
[0] 
[0] TypeError: grid.mongo.GridStore is not a constructor
[0]     at new GridReadStream (/home/lenovo/Desktop/react/cstore/node_modules/gridfs-stream/lib/readstream.js:68:17)

This is server.js

      app.get('/image/:filename', (req, res) => {
    gfs.files.findOne({ 
      _id: mongoose.Types.ObjectId(req.params.filename)
      // filename: req.params.filename.toString()
    }, (err, file) => {
      // Check if file
      if (!file || file.length === 0) {
        console.log("not found")
        return res.status(404).json({
          
          err: 'No file …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js gridfs multer-gridfs-storage

4
推荐指数
1
解决办法
4468
查看次数