【问题标题】:meteor fs.collection 500 error after insert image插入图像后流星 fs.collection 500 错误
【发布时间】:2015-07-29 10:03:44
【问题描述】:

我正在尝试使用 FS.Collection2 库 https://github.com/CollectionFS/Meteor-CollectionFS 在流星中上传工作图像

我设法上传图片并显示它们,但插入图片后出现以下服务器错误(我只插入,不更新任何内容)

 Exception while invoking method '/cfs.images.filerecord/update' Error: Did not check() all arguments during call to '/cfs.images.filerecord/update'

这是我的代码:

插入:

FS.Utility.eachFile(event, function(file) {
    Images.insert(file, function (err, fileObj) {
        console.log(err);
    });
});

收藏:

Images = new FS.Collection("images", {
    stores: [new FS.Store.FileSystem("images")]
});


if (Meteor.isServer) {
        Images.allow({
        insert: function (fileID, doc) {
            return true;
        },
        update: function (fileID, doc) {
            return true;
        },
        remove: function(userId, doc) {
            return false;
        },
        download: function (fileID, doc) {
            return true;
        }
    });
}

FS 包版本:

cfs:filesystem              0.1.1  
cfs:standard-packages       0.5.3

谢谢,希望你能指出正确的方向

我添加了错误的屏幕截图。

【问题讨论】:

    标签: meteor


    【解决方案1】:

    在你的流星应用上试试这个,告诉我是否有效,

    首先,为了更好地声明 /lib/collections.js folder 上的集合,请使用它。

    Images = new FS.Collection("images", {
      stores: [new FS.Store.FileSystem("images")]
    });
    
    if(Meteor.isClient) {
     Meteor.subscribe('Images');
     }
    

    同样在meteor控制台meteor remove autopublish insecure上,有了这个你所有的收藏都安全了,而且第一件事meteor将它加载到/lib文件夹,所以现在收藏在客户端/服务器上都可用

    现在在/server/collections.js

    Meteor.publish('Images', function(){
          return Images.find();
       });
    Images.allow({
    insert: function(userId, doc) { return true; },
    update: function(userId,doc) { return true; },
    remove: function(userId,doc) { return false; },
    download: function(userId, doc) {return true;},
    });
    

    现在在 /client/insertingImages.html 上,用一些简单的例子

      <template name="example">
        <input id="addImage" type="file">
        <button type="submit" id="loadImage"> Click to add Image</button>
        </template>
    

    现在/client/insertingImages.js

    Template.example.events({
      'click #loadImage' : function(template,event){
         var file = $('#addImage').get(0).files[0],
             metadataText = "this is some cool metadata text on the image";
             fsFile = new FS.File(file);
             fsFile.metadata = {textFile:metadataText}
         //Some authentication,(if not file selected cannot upload anything)
         if(file === undefined){
             alert("SORRY YOU NEED TO UPLOAD AN IMAGE TO CONTINUE");
            } else{
              Images.insert(fsFile,function(err,succes){
                if(err){
                  console.log(err.reason);
                  } else{
                   console.log(succes); //this should return the fsFile, or the Id of fsFile
                   }
               }
            }
      }
     })
    

    告诉我这是否有效

    【讨论】:

    • 您好 Etjana,非常感谢您的回复(我完全按照您所说的粘贴了您的代码),它的行为方式完全相同。上传并保存图片,但插入后出现服务器错误。我粘贴了几个错误的屏幕截图
    • 删除allow 上的userId,doc 参数似乎是来自服务器代码的问题,它抱怨并非所有arguments 都得到检查,尝试删除2 个参数
    • 好吧,我修复了它,我删除了 audit-argument-checks 数据包存在一些不兼容问题。不过谢谢回复!! :)
    【解决方案2】:

    如果你还没有弄清楚怎么做,那么在你的项目目录下的控制台中执行以下命令:

     meteor remove audit-argument-checks
    

    这将修复错误。

    【讨论】:

      猜你喜欢
      • 2015-09-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 2017-03-31
      • 2013-05-20
      • 2017-03-20
      • 1970-01-01
      相关资源
      最近更新 更多