mongodbsails.jsgridfssails-skipper

Sailsjs skipper-gridfs not working after upgrade to node v14


Library skipper-gridfs stopped working properly after upgrade node from v12 to v14. Is someone experiencing the same issue?.

Uploading files seems it works, even whenDone() is triggered and a file descriptor been created but when I need to retrieve the file it doesn't exists giving the following error:

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)

Is caused by node v14 given if I turn to v12 it works but i cannot use it given it has to coexist with an Angular9 instance.

So I attach the code I use for uploading and downloading just in case but it has no secret given worked for months with node v12:

Download:

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));
  }
});

}

Upload:

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);
});

} };


Solution

  • After a bit of research we gave a try to Amazon S3 buckets and it's SailsJS connector(skipper-s3). Works perfectly together, and we think it's a better alternative in our case, so we've obviated skipper-gridfs and worth for us getting a better solution.

    Now, after few months skipper-gridfs seems it's going to be fixed allowing compatibility with Node v14. For now only with a Dani Medina's fork of skipper-gridfs while his PRs(#44 and #45) are not merged to the official package.

    Info from my official github issue