hi everyone i using collectionfs + gridfs + cfs filesystem, on collectionfs documentation i find how to insert file on client side like this :
Template.myForm.events({
'change .myFileInput': function(event, template) {
FS.Utility.eachFile(event, function(file) {
Images.insert(file, function (err, fileObj) {
//Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
});
});
}
});
on that case will insert file on client side, but in my case i remove insecure, so can't do insert on client side, i try to make it on server side . so this is my code :
Template.myForm.events({
'change . myFileInput': function (event, template) {
FS.Utility.eachFile(event, function (file) {
var reader = new FileReader();
reader.onload = function (fileLoadEvent) {
Meteor.call('ImageUpload', file, reader.result, function (err, res) {
if (err) {
console.log(err);
} else {
alert(res);
}
});
};
reader.readAsBinaryString(file);
});
}
});
server.js :
Meteor.methods({
ImageUpload: function (fileInfo, fileData) {
console.log(fileInfo);
Images.insert(fileInfo, fileData, function (err, fileObj) {
if (err) console.log(err)
else {
//Inserted new doc with ID fileObj._id, and kicked off the data upload using HTTP
console.log(fileObj);
return fileObj._id;
}
});
}
});
but it still doesn't work, please help me how to fix this. how to insert on server side?
make sure to apply allow and deny rules like so:
Update must also be applied if using streaming
An example for you. I didnt tested it but it shows the way you have to go.
First define a collection:
I think this step is already clear to you.
Add added some filters. Just in case you need something like that.
Now you can define in the same *.js file your allow and deny functions. If you remove the insecure package all inserts/updates/removes have to pass allow/deny functions. If a command passes the allow callback it can be inserted into your collection (If there is no deny function that invalidates it)
Well in this example i just like to insert an image if there is a user and if the metadata user of the image is the user itself. You have to set the metadata user on your own. For testing just return true in every allow function, like shown in the example of Pent. Check the meteor documentation to read more about allow/deny http://docs.meteor.com/#allow
The client template should work as you posted. Just in case you want to use some metadata i added a bigger example.
This should be everything you need to have.