使用Meteor-CollectionFS上传Meteor文件,找不到错误方法

Asi*_*har 3 meteor collectionfs

我正在使用以下meteor包上传图像

https://github.com/CollectionFS/Meteor-CollectionFS

我正在使用的代码

Uploads =new FS.Collection('uploads',{
  stores: [new FS.Store.FileSystem('uploads',{path:'~/projectUploads'})]
});

if (Meteor.isClient) {

  Template.makedobox3.events({

       'change .fileinput':function(event,template){
        FS.Utility.eachFile(event,function(file){
        var fileObj=new FS.File(file);
        Uploads.insert(fileObj,function(err){
            console.log(err);
        });


      })
   }
  });  
}
Run Code Online (Sandbox Code Playgroud)

我尝试在控制台中上传文件时收到错误

M ... rm ... e.errorClass {错误:404,原因:"未找到方法",详情:未定义,消息:"找不到方法[404]"

我在窗口环境中.安装了自动发布和不安全的软件包.我不确定我错过了什么?

Aks*_*hat 5

确保您还在服务器端定义此集合:

Uploads =new FS.Collection('uploads',{
    stores: [new FS.Store.FileSystem('uploads',{path:'~/projectUploads'})]
});
Run Code Online (Sandbox Code Playgroud)

它无法找到该方法的原因是集合未在服务器端(在/server文件夹中)或在if(Meteor.isServer) {代替运行的代码块中定义if(Meteor.isClient).

另一种选择是Meteor是同构的,因此您可以从Meteor.isClient块中移动集合定义,以便它在客户端和服务器上运行.