问题
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);
}
});
});
回答1:
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/
来源:https://stackoverflow.com/questions/27633360/set-default-profile-picture-for-parse-signup