[英]Sailsjs skipper-gridfs not working after upgrade to node v14
Library skipper-gridfs stopped working properly after upgrade node from v12 to v14.将节点从 v12 升级到 v14 后,库 skipper-gridfs 停止正常工作。 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:上传文件似乎可行,即使触发了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)
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.是由节点 v14 引起的,如果我转向 v12 它可以工作,但我不能使用它,因为它必须与 Angular9 实例共存。
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:所以我附上了我用来上传和下载的代码,以防万一,但它没有任何秘密,因为它在节点 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);
});
} }; } };
After a bit of research we gave a try to Amazon S3 buckets and it's SailsJS connector( skipper-s3 ).经过一番研究,我们尝试了 Amazon S3 存储桶,它是 SailsJS 连接器 ( 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.完美地协同工作,我们认为它在我们的案例中是一个更好的选择,所以我们已经避免了
skipper-gridfs
并且值得我们获得更好的解决方案。
Now, after few months skipper-gridfs
seems it's going to be fixed allowing compatibility with Node v14.现在,几个月后,
skipper-gridfs
似乎将得到修复,允许与 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.目前只有Dani Medina 的skipper-gridfs 分支,而他的 PR( #44和#45 )没有合并到官方的 package。
Info from my official github issue来自我的官方 github 问题的信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.