我在服务器端使用 Ostrio/files(也称为流星文件(来自 VeliovGroup 或keenethics))将文件插入到 db.images、db.fs.files 和 db.fs.chunks。我的代码只能在 db.images 中插入一条记录,而在 fs.files 和 fs.chunks 上没有任何内容。我的代码如下:
Images.write(this.bodyParams.file, {
fileName: 'SignUpTermsAndConditions_' + this.bodyParams.name,
fielId: 'abc123myId', //optional
type: 'application/vnd.oasis.opendocument.text',
meta: {owner: this.userId,createdAt: new Date()}
}, function (error, fileRef) {
if (error) {
throw error;
} else {
console.log(fileRef.name + ' is successfully saved to FS. _id: ' + fileRef._id);
}
});
我可以使用以下代码将来自客户端的文件插入 db.images、db.fs.files 和 db.fs.chunks:
Images.insert({
file: file, // where var file = e.currentTarget.files[0];
fileName: fileName + e.currentTarget.files[0].name,
onStart: function () {
},
onUploaded: function (error, fileObj) {
if (error) {
alert('Error during upload: ' + error);
} else {
}
},
streams: 'dynamic',
chunkSize: 'dynamic'
});
上面第一个片段的服务器代码不能正常工作或按预期工作。请帮助。
有关信息:我如何设置我的 gridFS 是按照 这个链接。我的 Images.write 按照我上面的第二个代码片段是按照 这个链接中的代码。简而言之,我正在关注文档,但我的服务器 Images.write 没有按预期工作。请帮忙!