I am new to Meteor and I want to know how we can ask the user to upload his image while creating an account? I am using basic Meteor accounts
for creating user accounts. I want user to be able to upload his image and also be able to show it when he logs in and on the landing page for my website(i.e even when the user is not logged in!).
I need pointers on the same.
Is there any extra package that helps doing this. A tutorial or a code snippet will help a lot.
Regards.
Use https://github.com/CollectionFS/Meteor-CollectionFS to upload and store image.
'change #profile-image-input': function(event, template) {
var files = event.target.files;
console.log(files);
for (var i = 0, ln = files.length; i < ln; i++) {
Session.set('isUploading', true);
Collections.ProfileImages.insert(files[i], function (err, fileObj) {
if(err){
Session.set('isUploading', false);
toast('Please Select An Image To Upload')
}else{
Session.set('imageUrl',fileObj._id);
}
});
}
},
The Image.insert()
returns document object id which you can use to retrieve the profile image, I'd recommend once upload is complete get the _id and store it in user profile.