是否可以直接将Swift中的PFFiles传递给Cloud Code并将其设置在对象上?
我有一个PFFile,
let imageData = UIImageJPEGRepresentation(self.imageView.image!, 0.1)
let imageFile = PFFile(data: imageData!)
我尝试将其设置在用户对象上,然后在云代码中进行签名,如下所示:
Parse.Cloud.define("createNewUser", function(request, response) {
var theimage = request.params.image
var username = request.params.username
var pw = request.params.password
var user = new Parse.User();
user.set("username", username);
user.set("password", pw);
theimage.save().then(function(){
user.set("image",theimage)
user.signUp(null, {
success: function(user) {
response.error("working");
},
error: function(user, error) {
response.error("Sorry! " + error.message);
} });
}, function(error) {
response.error("Sorry! " + error.message);
});
});
调用云代码的iOS代码:
PFCloud.callFunctionInBackground("createNewUser", withParameters:
["username": username, "password": password, "image": imageFile],
block: { (result, error) -> Void in
// UI stuff
})
我收到此错误:
TypeError: Cannot read property 'format' of undefined
at e.a.value (Parse.js:13:25673)
at main.js:40:14 (Code: 141, Version: 1.10.0)
我试着看看这个:http://parse.com/docs/js/api/classes/Parse.File.html我仍然不确定如何将我的图像从Swift转换为云代码,以便我可以注册新用户...
答案 0 :(得分:0)
我没有将图像作为PFFile传递,而是将图像作为NSData传递,然后将结果转换为Parse.File对象。然后我保存了它并签了用户。效果很好!
JS
var parseFile = new Parse.File("prof",theimage)
parseFile.save().then(function(){
user.set("image",parseFile)
user.signUp(null, {
success: function(user) {
response.success("working");
},
error: function(user, error) {
response.error("Sorry! " + error.message);
} });
}, function(error) {
response.error("Sorry! " + error.message);
});