集合FS 错误 - 未捕获的错误:集合 FS: 不支持文件切片



我在尝试将照片插入数据库时收到上述错误。奇怪的是,文档的文件端插入得很好,但没有任何东西插入到块端。我环顾了网络,但没有得到任何关于问题可能是什么的提示。有没有人看到这个错误并可以提供帮助?

这是我的代码。

收藏.js

PhotosFS = new CollectionFS('photos');
PhotosFS.allow({
    insert: function (userId, file) {
        return userId && file.owner === userId;
    }
});

事件.js

Template.createPhotos.events({
    "change input[type='file']": function (e, tmpl) {
        var file = e.target.files;
        Session.set('currentFile', file[0]);
   },
   "click .save-button": function (e, tmpl) {
         var file = Session.get('currentFile');
         PhotosFS.storeFile(file, {
              name: name,
              photographer: photographer,
              caption: caption,
         });
    }
});

我猜这与在上传到数据库之前将文件存储在会话中有关,因为如果您在输入文件更改后直接上传文件,它会上传得很好。当直接从输入文件更改事件上传时,它会作为文件上传。但是,当它存储在会话中然后上传时,它会作为对象上传。我猜 CollectionFS 块无法识别对象。我不知道。但我确实知道,对于我的特定应用程序,在输入文件更改事件后直接上传文件是没有意义的。

但我想我必须这样做

Template.createPhotos.events({
    "change input[type='file']": function (e, template) {
        var file = e.target.files;
        var fileId = PhotosFS.storeFile(file[0]);
        Session.set('currentFile', fileId)
    },
    "click .save-button": function (e, tmpl) {
        var file = Session.get('currentFile');
        PhotosFS.storeFile(file, {$set: {
            name: name,
            photographer: photographer,
            caption: caption,
        }});
    }
});

我不会接受我自己的答案,因为我仍然希望有人在上传之前找到一种方法将文件存储在会话中。

最新更新