Friday 14 August 2015

Filled Under:

Uploading image with userid, so that 1 can browse photogallery

iam writing this article and also uploading a project so that you can see how it works

i was stuck with this problem
in my project, i allow users to upload multiple images, and they are stored using cfs:filesystem
in 3 types as icon, as thumbnail and actual image

thumbnail images are required so that they show up in browse members and on the profile of the user
and when the user clicks on the members profile he is taken to that particular users photogallery

in order to do that you just need to modify file collection, so that it stores userid in cfs.images.filerecord collection

and the code is
'Template.myForm.events({
    'change .myFileInput': function(event, template) {
        FS.Utility.eachFile(event, function(file) {

var newfile=new FS.File(file)
newfile.userid=Meteor.userId();

            Images.insert(file, function (err, fileObj) {
                //If !err, we have inserted new doc with ID fileObj._id, and                //kicked off the data upload using HTTP            });
        });
    }
});'


the code marked in the red, is all that you got to do to insert userid in cfs.images.filrecord collection
so that you can link those images to a particular user

you can download source code from here

http://www.amincode.com/codes/viewcode?codeid=55cd9712cb64a32fe042636b




0 comments:

Post a Comment