升级到节点 v14 后 Sailsjs skipper-gridfs 不工作

Sailsjs skipper-gridfs not working after upgrade to node v14

库 skipper-gridfs 在将节点从 v12 升级到 v14 后停止正常工作。有人遇到同样的问题吗?

上传文件似乎有效,即使触发了 Done() 并创建了文件描述符,但当我需要检索文件时它不存在并出现以下错误:

Error: FileNotFound: file b33b78d2-30ea-4fe3-9228-2a8a7ccc8a77.PNG was not found
at /home/melich/Documents/becquel_backend/node_modules/skipper-gridfs/node_modules/mongodb/lib/gridfs-stream/download.js:284:17
at executeCallback (/home/melich/Documents/becquel_backend/node_modules/skipper-gridfs/node_modules/mongodb/lib/operations/execute_operation.js:70:5)
at handleCallback (/home/melich/Documents/becquel_backend/node_modules/skipper-gridfs/node_modules/mongodb/lib/utils.js:128:55)

是由节点 v14 引起的,如果我转向 v12 它可以工作,但我不能使用它,因为它必须与 Angular9 实例共存。

所以我附上了我用于上传和下载的代码以防万一,但它没有给出在节点 v12 上工作了几个月的秘密:

下载:

download: async function (req, res) {
var blobAdapter = require('skipper-gridfs')({
  uri: 'mongodb://root:pASSWORD@127.0.0.1/files'
});

var fileID = req.param('id');
const fileModel = await Files.findOne({id: fileID});

blobAdapter.read(fileModel.fd, function(error , file) {
  if(error) {
    console.log(error);
    res.json(error);
  } else {
    res.contentType(fileModel.contentType);
    res.send(new Buffer(file));
  }
});

}

上传:

uploadFile: function (req, res) {
const budgetID = req.param('id');
const scope = req.param('scope');
req.file('file').upload({
  // don't allow the total upload size to exceed ~10MB
  maxBytes: 2 * 10000000,
  adapter: require('skipper-gridfs'),
  uri: 'mongodb://root:pASSWORD@127.0.0.1/files'    
}, async function whenDone(err, uploadedFiles) {
  if (err) {
    return res.serverError(err);
  }

  // If no files were uploaded, respond with an error.
  if (uploadedFiles.length === 0){
    return res.badRequest('No file was uploaded');
  }

  var file = await Files.create({
    fd: uploadedFiles[0].fd,
    name: uploadedFiles[0].filename,
    contentType: uploadedFiles[0].type,
    scope: scope,
    groupID: req.session.userData.group,
    userID: req.session.userData.id
  }).fetch();

  await Budget.addToCollection(budgetID, 'files').members([file.id]);

  return res.ok(file);
});

} };

经过一些研究,我们尝试了 Amazon S3 存储桶和它的 SailsJS 连接器 (skipper-s3)。一起完美工作,我们认为在我们的案例中这是一个更好的选择,所以我们已经避免了 skipper-gridfs 并且值得我们获得更好的解决方案。

现在,几个月后 skipper-gridfs 似乎它会得到修复,允许与 Node v14 兼容。目前只有一个 Dani Medina's fork of skipper-gridfs while his PRs(#44 and #45) 没有合并到官方包中。

信息来自 my official github issue