Reputation: 1611
I'am trying to make work image upload in meteor using FS.Collection2 library https://github.com/CollectionFS/Meteor-CollectionFS
I manage to upload pictures and show them, but after I insert an image I get the following server error (I only insert, I don't update anything)
Exception while invoking method '/cfs.images.filerecord/update' Error: Did not check() all arguments during call to '/cfs.images.filerecord/update'
This is my code:
insert:
FS.Utility.eachFile(event, function(file) {
Images.insert(file, function (err, fileObj) {
console.log(err);
});
});
collection:
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images")]
});
if (Meteor.isServer) {
Images.allow({
insert: function (fileID, doc) {
return true;
},
update: function (fileID, doc) {
return true;
},
remove: function(userId, doc) {
return false;
},
download: function (fileID, doc) {
return true;
}
});
}
FS Packages versions:
cfs:filesystem 0.1.1
cfs:standard-packages 0.5.3
Thanks hope you can point me in the right direction
I added screen captures of the error.
Upvotes: 1
Views: 948
Reputation: 381
If you still have not figured out how to do it, then execute the following command in the console in your project directory:
meteor remove audit-argument-checks
This will fix the error.
Upvotes: 0
Reputation: 11376
try this on your meteor app, and tell me if works,
First, for better declarations of Collections on the /lib/collections.js folder
, use this.
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images")]
});
if(Meteor.isClient) {
Meteor.subscribe('Images');
}
Also on meteor console, meteor remove autopublish insecure
, and with this you have all collection safe, and also the first thing meteor loads it the /lib
, folder so the collection now are available on both client/server
now on the /server/collections.js
Meteor.publish('Images', function(){
return Images.find();
});
Images.allow({
insert: function(userId, doc) { return true; },
update: function(userId,doc) { return true; },
remove: function(userId,doc) { return false; },
download: function(userId, doc) {return true;},
});
Now on /client/insertingImages.html
, use some simple example
<template name="example">
<input id="addImage" type="file">
<button type="submit" id="loadImage"> Click to add Image</button>
</template>
now on /client/insertingImages.js
Template.example.events({
'click #loadImage' : function(template,event){
var file = $('#addImage').get(0).files[0],
metadataText = "this is some cool metadata text on the image";
fsFile = new FS.File(file);
fsFile.metadata = {textFile:metadataText}
//Some authentication,(if not file selected cannot upload anything)
if(file === undefined){
alert("SORRY YOU NEED TO UPLOAD AN IMAGE TO CONTINUE");
} else{
Images.insert(fsFile,function(err,succes){
if(err){
console.log(err.reason);
} else{
console.log(succes); //this should return the fsFile, or the Id of fsFile
}
}
}
}
})
Tell me if this works
Upvotes: 3