Reputation: 173
Is There a way to store file in Meteor Apps? if yes how?
Also how can i store file data in user defined collections using meteor?
I didn't get any idea about this.
Thanks in Advance.
Upvotes: 0
Views: 254
Reputation: 11376
The best way to store files into MeteorJs is using the FSCollection Package.
This question already have an answer here
I Made a little Demo and here is the Source Code
In Resume just run this 2 commands
meteor add cfs:standard-packages
meteor add cfs:gridfs
Declare a simple FScollection
Images = new FS.Collection("Images", {
stores: [new FS.Store.GridFS("Images")]
});
and do this simple Event Handler.
Template.exampe.events({
'click #addImage':function(){
var file = $('#inputPng').get(0).files[0],
fsFile = new FS.File(file);
//and also store file data in user defined collections using meteor
fsFile.metadata = {
ownerId:Meteor.userId(),
title:$(e.target).find('#submit-title').val()
}
Images.insert(fsFile,function(err,result){
if(!err){
console.log(result)
}
})
}
})
Upvotes: 1