Insert data to CollectionFS (cfs:filesystem cfs:standard-packages)


#1

hi , i’m new here , i’m using cfs:filesystem
cfs:standard-packages on upload image , everything work fine but i don’t know how to insert data to collection by myself , it’s alway insert data automatically !

example : Collection
{
"_id" : “YsWDohDkjEPZ2a6p6”, // _id here i need generate to 001
"userId": “0001” // here i want to insert new filed userId to collection
"original" : {
“name” : “100APPLE_IMG_0167.JPG”,
“updatedAt” : ISODate(“2013-01-07T14:54:13.000Z”),
“size” : 368287,
“type” : “image/jpeg”
},
“uploadedAt” : ISODate(“2015-06-04T17:39:15.964Z”),
“copies” : {
“yourFileCollection” : {
“name” : “100APPLE_IMG_0167.JPG”,
“type” : “image/jpeg”,
“size” : 368287,
“key” : “yourFileCollection-YsWDohDkjEPZ2a6p6-100APPLE_IMG_0167.JPG”,
“updatedAt” : ISODate(“2015-06-04T17:39:15.000Z”),
“createdAt” : ISODate(“2015-06-04T17:39:15.000Z”)
}
}
}

thank you for advance !


#2

in the insert function you can pass anpther anonimous function as a second parameter and it can contain something like this
fileObj.parameterName= parameterValue;


#3

Hey @yousour ,

I’m using cfs:gridFS instead of cfs:filesystem, but I think that doesn’t matter.

I did it like this:

Template.myTemplate.events({
  'change .myFileinput': function(event, template) {
	FS.Utility.eachFile(event, function(file) {
		var tmpdoc 	= new FS.File(file);
		tmpdoc.myString = "This is my cool Text";
		tmpdoc.myDate	= new Date();
		
		Images.insert(tmpdoc, function (err) {});
	});
  }
});

Hope this helps.


#4

ok , thank you for your help !