Hi guys!
Just getting started with Meteor. It’s amazing, but I’ve run into a couple of issues due to my noobness
I’m struggling to implement user profile photos and get gridfs up and running. This is the error I’m getting:
Exception in template helper: TypeError: Cannot read property ‘image’ of undefined.
Here is the relevant code:
common.js
Template.registerHelper('getProfileImg', function (userId) {
var imgUrl = UserImages.findOne({userId: userId}).image;
return imgUrl;
});
posts.html
<img src="{{getProfileImg userId}}">
profile.js
Template.profile.events({
'submit .edit-profile': function (event) {
var file = $('#profileImage').get(0).files[0];
if(file){
fsFile = new FS.File(file);
ProfileImages.insert(fsFile, function(err, result){
if(err) {
throw new Meteor.error(err);
} else {
var imageLoc = '/cfs/files/ProfileImages/'+result._id;
UserImages.insert({
userId: Meteor.userId(),
username: Meteor.user().username,
image: imageLoc
});
Router.go('/');
}
});
}
return false;
}
});
Any help would ge greatly appreciated