Hi everyone,
I’m quite new to Meteor but really enjoying using it! It almost feels like cheating, it’s so easy to do so much.
However, it’s not all sunshine and rainbows. I’ve run into a problem with CollectionFS and gridFS. I want my users to upload their avatar and be able to change it. But I can’t seem to get any kind of upload to work?
Here’s my code so far, any pointers or (preferably) any example code would be greatly appreciated!:
/server/images.js
var avatarStore = new FS.Store.GridFS("avatars");
Avatars = new FS.Collection("avatars", {
stores: [avatarStore]
});
/client/app.js
var avatarStore = new FS.Store.GridFS("avatars");
Avatars = new FS.Collection("avatars", {
stores: [avatarStore]
});
Template.editProfile.events({
'change #avatarUp': function(event, template) {
FS.Utility.eachFile(event, function(file) {
Avatars.insert(file, function (err, fileObj) {
if (err){
// handle error
} else {
// handle success depending what you need to do
var userId = Meteor.userId();
var avatarURL = {
"profile.avatar": "/cfs/files/images/" + fileObj._id
};
Meteor.users.update(userId, {$set: avatarURL});
}
});
});
}
});
To be honest, I feel like I don’t fully understand the way CollectionFS works. That’s partly down to the documentation though, as I feel I have a grasp of Meteor as a whole to be honest.
It’s worth mentioning that if I run the command: Meteor.user().profile.avatar;
in the console I do get a return of “/cfs/files/images/JQzMbq7YcCfQRaxT6” as an example. So something is working, I just don’t know from here how to retrieve anything.
Last but not least, when I do try upload anything I get this error in the console:
“The provided value ‘undefined’ is not a valid enum value of type XMLHttpRequestResponseType.”
Again, any help would be greatly appreciated! I’m sure most of you are a lot better at this than I am.
Cheers,
Tom.