尝试在Xcode和Parse中将图像保存在后台时出错

时间:2019-04-21 11:49:28

标签: swift parse-platform parse-server parse-ios-sdk

我正在尝试将图像保存在随AWS启动的Parse服务器上。当我按下postImage按钮时,我看到以下错误消息:

  

“由于格式不正确,无法读取数据”

。我的Xcode版本是10.2.1

如果在没有图像文件正常工作的情况下保存数据,则会在解析服务器上创建该类,并添加注释和用户objectIds。

这是按钮中的代码:

@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和图像文件创建该类。但是甚至没有直接创建类,因为它直接进入了错误管理

0 个答案:

没有答案