Hi guys,
I have an app that lets users sign up. Whenever a user signs up, I want to upload a default avatar image for them on Parse. I’m currently trying to do this using parse cloud code.
Parse.Cloud.beforeSave("Profile", function(request, response) {
if (!request.object.get("photo")) {
var pic =
{
"name": request.object.get("phone") + '-avatar',
"__type": "File",
"url": 'http://files.parsetfss.com/1ad00c84-7830-427f-ac8d-d4459361b5ce/tfss-905a97f8-9505-4ab1-aabc-5c3aef44cd35-avartar.jpeg'
};
request.object.set("photo", pic);
}
response.success();
});
And here is the code where the user is being signed up:
user.signUp(null, {
success: function (user) {
var Profiles = Parse.Object.extend("Profiles");
var newProfile = new Profiles();
$window.localStorage['user'] = JSON.stringify(user);
newProfile.set("userid", user.id);
newProfile.set("fullname", $scope.credentials.fullname);
newProfile.set("shortBio", $scope.credentials.shortBio);
newProfile.set("phone", $scope.credentials.phone);
newProfile.set("settings", $scope.settings);
newProfile.set("fhomies", $scope.credentials.fhomies);
newProfile.set("favorites", $scope.credentials.favorites);
newProfile.set("reservations", $scope.credentials.reservations);
newProfile.set("userdetails", user);
// var file = '../img/profile-avatar.jpeg';
// var avatar = new Parse.File(user.id + ' avatar', {base64: ''});
// console.log(avatar);
// newProfile.set("photo", avatar);
newProfile.save(null, newProfile).then(function (profile) {
$window.localStorage['userprofile'] = JSON.stringify(profile);
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$scope.loading = false;
$state.go('funkythar.activity');
}, function (error) {
$scope.loading = false;
$ionicPopup.alert({
title: 'Oops!',
template: 'There was a problem creating your profile details'
});
});
},
error: function (user, error) {
$scope.loading = false;
$ionicPopup.alert({
title: 'Oops!',
template: 'Error: ' + ' Something Went Wrong, Try again '
});
}
});
This method does not upload the avatar image to parse. I cant figure out what I’m doing wrong. Maybe I’m using beforeSave wrongly or I’m missing some save parameters.
Thanks for your help.