成功保存后,我无法让我的JPEG图像显示在Parse上。这是我的代码:
BOOL
代码运行并且所有内容都正确存储在Parse中,除了图像仍然是“未定义”,但我的print语句返回:
var createPost = PFObject(className: "Loading_Post") createPost["userObjectId"] = PFUser.currentUser()?.objectId let imageOne = image1.image as UIImage! let imageData1 = UIImageJPEGRepresentation(imageOne, 0.5) let imageFile1 = PFFile(name: "image1.jpg", data: imageData1!) print(imageFile1) createPost["image1"] = imageFile1 createPost.saveInBackgroundWithBlock { (success, error) -> Void in if error == nil { self.displayAlert("success! ", message: "Your Post has been saved successfully") } else { self.displayAlert("Could not post image", message: "Please try again later") } }
谢谢!
答案 0 :(得分:1)
您可能需要首先保存PFFile
图像,然后将其保存到PFObject
。试试这个,
imageFile1.saveInBackgroundWithBlock { (success, error) -> Void in
if error == nil {
var createPost = PFObject(className: "Loading_Post")
createPost["userObjectId"] = PFUser.currentUser()?.objectId
createPost["image1"] = imageFile1
createPost.saveInBackgroundWithBlock { (success, error) -> Void in
if error == nil {
self.displayAlert("success! ", message: "Your Post has been saved successfully")
} else {
self.displayAlert("Could not post image", message: "Please try again later")
}
} else {
self.displayAlert("Could not post image", message: "Please try again later")
}
答案 1 :(得分:0)
尝试保存解析时,这是一个简单的拼写错误。 "图像1"应该是" Image1"。很抱歉没有抓住这个!