Skip to content

Instantly share code, notes, and snippets.

@jamiechapman
Last active August 29, 2015 14:01
Show Gist options
  • Save jamiechapman/511e05f51288de3c6ed2 to your computer and use it in GitHub Desktop.
Save jamiechapman/511e05f51288de3c6ed2 to your computer and use it in GitHub Desktop.
Parse.Cloud.afterSave("Upload", function(req) {
if(req.user) {
if(req.object.has('type') && req.object.has('file')) {
var type = req.object.get('type');
if(type === 'avatar') {
console.log("Saving file..." + req.user.id);
// Switch to the master key
Parse.Cloud.useMasterKey();
var user = Parse.User.current();
user.set('avatar', req.object.get('file'));
user.save(null).then(function(u) {
console.log("Updated User_");
// Delete the original Upload object!
req.object.destroy({});
}, function(e) {
console.log("Error saving User_ " + e);
});
} else {
console.log("Unknown image type!");
}
} else {
console.log("Invalid Params");
}
} else {
console.log("Unauthenticated");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment