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

985 views Asked by At

I am using following meteor package to upload the image

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

Code I am using

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


      })
   }
  });  
}

I am getting error when I try to upload a file in console

M…r.m…e.errorClass {error: 404, reason: "Method not found", details: undefined, message: "Method not found [404]"

I am on window environment. Auto-publish and insecure packages are installed. I am not sure what I am missing?

1

There are 1 answers

2
Tarang On BEST ANSWER

Make sure you also define this collection on the server side:

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

The reason it can't find the method is the collection isn't defined on the server side (in the /server folder) or in a block of code that runs in if(Meteor.isServer) { instead of if(Meteor.isClient).

One alternative is Meteor is isomorphic, so you can just move the collection definition from the Meteor.isClient block so it runs on both the client and server.