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

Meteor file upload with Meteor-CollectionFS giving error method not found

我正在使用以下流星包上传图片

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


      })
   }
  });  
}

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

M…r.m…e.errorClass {错误:404,原因:"Method not found",详情:未定义,消息:"Method not found [404]"

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

确保您也在服务器端定义了这个集合:

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

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

另一种选择是 Meteor 是同构的,因此您只需将集合定义从 Meteor.isClient 块中移出,这样它就可以在客户端和服务器上运行。