【问题标题】:CollectionFS error - Uncaught Error: CollectionFS: file.slice not supported?CollectionFS 错误 - 未捕获的错误:CollectionFS:不支持 file.slice?
【发布时间】:2014-02-12 06:08:59
【问题描述】:

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

这是我的代码。

collections.js

PhotosFS = new CollectionFS('photos');

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

events.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,
         });
    }
});

【问题讨论】:

    标签: meteor


    【解决方案1】:

    我猜这与在上传到数据库之前将文件存储在会话中有关,因为如果您在输入文件发生更改后直接上传文件,则上传正常。当它直接从输入文件更改事件上传时,它作为文件上传。但是当它存储在会话中然后上传时,它会作为对象上传。我猜 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,
            }});
        }
    });
    

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

    【讨论】:

      猜你喜欢
      • 2016-09-05
      • 2014-08-08
      • 2020-08-18
      • 2014-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多