【问题标题】:Meteor file upload with Meteor-CollectionFS giving error method not found使用 Meteor-CollectionFS 上传 Meteor 文件时未找到错误方法
【发布时间】:2015-09-03 20:23:54
【问题描述】:

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

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 {error: 404, reason: "Method not found", details: undefined, message: "Method not found [404]"

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

【问题讨论】:

    标签: meteor collectionfs


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 非常感谢。我是初学者,这真的很有帮助。
    • 非常感谢! =D
    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多