我正在尝试将图像保存在使用 AWS 启动的 Parse 服务器上。当我按下 postImage 按钮时,我看到以下错误消息:
“无法读取数据,因为它的格式不正确”
. 我的Xcode版本是10.2.1
如果我在图像文件不工作的情况下保存数据,则会在解析服务器上创建类,并添加注释和用户 objectId。
这是按钮中的代码:
@IBOutlet weak var comment: UITextField!
@IBOutlet weak var imageToPost: UIImageView!
@IBAction func postImage(_ sender: Any) {
if let image = imageToPost.image {
// Create the class object for the Post
let post = PFObject(className: "Post")
post["Message"] = comment.text
post["userId"] = PFUser.current()?.objectId
// Create the image data
if let imageData = image.pngData() {
let imageFile = PFFileObject(name: "image.png", data: imageData)
post["imageFile"] = imageFile
post.saveInBackground { (success, error) in
if let error = error {
print("There were issues saving the file: \(error.localizedDescription)")
self.displayAlert(title: "Error", message: "Image could not be posted, please try again later")
} else {
// SAving successful
print("File saved correctly")
self.displayAlert(title: "Image Posted", message: "Your image hase posted successfully")
self.comment.text = ""
self.imageToPost.image = nil
}
}
}
}
}
所以我希望这个类是用评论、userId 和图像文件创建的。但是该类甚至没有被创建,因为它直接进入错误管理