I have tried a lot to post json data with an image, to a REST API using curl- command line interface, but could not succeed in it. The request I tried was:
curl -X POST -H "X-Parse-Application-Id: sdgfsdfgsdfgsdfgsdfgsdg" -H "Content-Type: multipart/form-data" -H "X-Parse-REST-API-Key: sdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdg" -d '{"username":"aaaaaaaa","email":"aaaaaaaaa@gmail.com","password":"123"}' --data-binary "image:@/home/user/Pictures/gravatar.jpg" https://api.parse.com/1/functions/signUpUser
I also tried this:
curl -X POST -H "X-Parse-Application-Id: sdgfsdfgsdfgsdfgsdfgsdg" -H "X-Parse-REST-API-Key: sdfgsdfgsdfgsdfgsdfgsdfgsdfgsdfgsdg" -d '{"username":"aaaaaaaa","email":"aaaaaaaaa@gmail.com","password":"123"}' --data-binary "image:@/home/user/Pictures/gravatar.jpg" https://api.parse.com/1/functions/signUpUser
I am trying to upload an image as well as some data onto parse.com (using cloud code), but I am always facing the issue :
{"code":141,"error":"TypeError: Cannot call method 'then' of undefined\n at Object.b.File.save (Parse.js:2:15208)\n at main.js:10:15"}
The following is my cloud function:
Parse.Cloud.define("signUpUser",function(request,response) {
var user = new Parse.User();
user.set("username", request.params.username);
user.set("password", request.params.password);
var parseFile = new Parse.File("imgTest.jpg", request.files.image);
parseFile.save().then(function() {
user.set("gravatar", parseFile);
user.set("email", request.params.email);
if (validateWithRegEx(request.params.username,"email")) {
user.signUp(null, {
success: function(user) {
response.success("signed up!!!");
},
error: function(user, error) {
response.error("Error: " + error.code + " " + error.message);
}
});
}
else {
response.error("Invalid email");
}
}, function(error) {
response.error("file save error");
});
Please someone help me.