Last active
August 29, 2015 14:01
-
-
Save jamiechapman/511e05f51288de3c6ed2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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