插入图像后流星 fs.collection 500 错误 [英] meteor fs.collection 500 error after insert image

查看:25
本文介绍了插入图像后流星 fs.collection 500 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'am trying to make work image upload in meteor using FS.Collection2 library https://github.com/CollectionFS/Meteor-CollectionFS

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

I manage to upload pictures and show them, but after I insert an image I get the following server error (I only insert, I don't update anything)

 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

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

Thanks hope you can point me in the right direction

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

I added screen captures of the error.

推荐答案

在你的meteor 应用上试试这个,如果有效,请告诉我

try this on your meteor app, and tell me if works,

首先,为了在 /lib/collections.js 文件夹 上更好地声明集合,请使用它.

First, for better declarations of Collections on the /lib/collections.js folder, use this.

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

if(Meteor.isClient) {
 Meteor.subscribe('Images');
 }

同样在meteor 控制台上,meteor remove autopublish insecure,这样你就拥有了所有收藏安全,而且meteor 将它加载到/lib 文件夹中,所以该集合现在可以在客户端/服务器上使用

Also on meteor console, meteor remove autopublish insecure, and with this you have all collection safe, and also the first thing meteor loads it the /lib, folder so the collection now are available on both client/server

现在在 /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 上,使用一些简单的例子

Now on /client/insertingImages.html , use some simple example

  <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
               }
           }
        }
  }
 })

告诉我这是否有效

这篇关于插入图像后流星 fs.collection 500 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆