调用方法' pushFile':使用meteor上传时出现内部服务器错误[500]

时间:2015-11-12 22:00:39

标签: meteor

我正在尝试将文件上传到服务器,但我一直在控制台中获取Error invoking Method 'pushFile': Internal server error [500]。我不确定这里发生了什么。我对流星来说几乎是全新的,任何帮助都会非常感激。

      Template.hello.events({
        'change .fileInput': function(event, template){
          event.preventDefault();
          // var theName = event.target.theName.value;
          console.log(theName);
          FS.Utility.eachFile(event, function(file){
            var fileObj = new FS.File(file);
            fileObj.itemtext = theName;
            Meteor.call("pushFile", fileObj);
          });
        }

      });


    }

    if(Meteor.isServer){
      Meteor.methods({
        'pushFile': function(fileObj){
        fileObj.userId = this.userId;
        Uploads.insert(fileObj, function(err){
            console.log(err);
          });
        }
      });
    }

其余错误如下:

I20151112-17:29:03.764(-5)? Exception while invoking method 'pushFile' Error: DataMan constructor received data that it doesn't support
I20151112-17:29:03.770(-5)?     at EventEmitter.FS.Collection.insert (packages/cfs_collection/packages/cfs_collection.js:269:1)
I20151112-17:29:03.770(-5)?     at [object Object].Meteor.methods.pushFile (uploadexample.js:39:21)
I20151112-17:29:03.769(-5)?     at new DataMan (packages/cfs_data-man/packages/cfs_data-man.js:75:1)
I20151112-17:29:03.770(-5)?     at setData (packages/cfs_file/packages/cfs_file.js:107:1)
I20151112-17:29:03.770(-5)?     at EventEmitter.fsFileAttachData [as attachData] (packages/cfs_file/packages/cfs_file.js:102:1)
I20151112-17:29:03.771(-5)?     at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20151112-17:29:03.771(-5)?     at livedata_server.js:708:19
I20151112-17:29:03.771(-5)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151112-17:29:03.772(-5)?     at livedata_server.js:706:40
I20151112-17:29:03.772(-5)?     at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)

1 个答案:

答案 0 :(得分:1)

在这里查看答案...... Meteor File Upload Not Working

  

当您需要插入位于客户端上的文件时,请始终在客户端上调用myFSCollection.insert。虽然您可以定义自己的方法,将其传递给fsFile,然后在服务器上调用myFSCollection.insert,但困难在于将数据从客户端传递到服务器。将fsFile传递给方法时,仅发送文件信息而不是数据。相比之下,当您直接在客户端上执行插入操作时,它会在插入后自动对文件的数据进行分块,然后将其排队以按块发送到服务器。然后就是重新组合服务器上的所有块并将数据填充回fsFile。因此,进行客户端插入实际上可以为您节省所有这些复杂的工作,这就是我们推荐它的原因。

然后为了保护插入,因为它来自客户端,设置允许/拒绝规则以决定谁可以在哪里插入。在您的服务器文件夹中,添加一个文件(通常是/server/allow/Uploads.js)这样的东西......

Uploads.allow({
  insert: function (userId, doc) {
    // the user must be logged in, and whatever other constraints you want
    return (userId && otherCoolSecurityCheckFunction());
  },
  update: function (userId, doc, fields, modifier) {
    // can only change your own documents
    return doc.owner === userId;
  },
  remove: function (userId, doc) {
    // can only remove your own documents
    return doc.owner === userId;
  },
  fetch: ['owner']
});

有关详细信息,请参阅允许文档...

http://docs.meteor.com/#/full/allow