2

I am trying to set default profile picture at signup time in parse.the picture is in my project folder. Is there any way to set it without photo upload.

var user = new Parse.User();
user.set("username", $('#username').val());
user.set("password", $('#password').val());
user.set("email", $('#email').val());
user.set("phone", $('#phone').val());
user.set("address", $('#address').val());
var parseFile = new Parse.File("profile.jpg", fileData, "image/jpg");
parseFile.save().then(function() {
    alert('done')
}, function(error) {
    alert(error.code);
});
user.set("image", parseFile);

user.signUp(null, {
    success: function(user) {
        alert("successfully insert")
    },
    error: function(user, error) {
        alert("Error: " + error.code + " " + error.message);
    }
});
});
Joachim Sauer
  • 505
  • 1
  • 8
  • 18
Aveek R.
  • 23
  • 4

1 Answers1

0

You can use Parse Config and Cloud Code for this purpose. Upload a default profile picture to a Config field called: defaultProfilePicture.

Then use this in Cloud Code:

Parse.Cloud.beforeSave(Parse.User, function (request, response) { //check if user being saved has profile picture. if (!request.object.has("profilePicture")) { Parse.Config.get().then(function(config) { request.object.set("profilePicture", config.get("defaultProfilePicture")); response.success(); }); } else { response.success(); } });

http://blog.parse.com/2014/09/08/announcing-parse-config/

Samuel Barbosa
  • 782
  • 7
  • 18
  • when running your code, the `function(config)` is never called.. if I add a `,function(error){}` after I can see it's always erroring ` {code: undefined, message: 'unauthorized' }` any idea? – Hugues BR Nov 10 '15 at 10:28