Swift 2, Xcode 7.2 'NSInternalInconsistencyException

Swift 2, Xcode 7.2 'NSInternalInconsistencyException

Error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not save file data for image.png : Error Domain=NSCocoaErrorDomain Code=263 "Failed to create PFFile with data: data is larger than 10MB." UserInfo={NSLocalizedDescription=Failed to create PFFile with data: data is larger than 10MB

使用 www.heroku.com 作为备用 parse.com。它使用 MonoLab 数据库,我正在尝试 post 将图像添加到我的数据库,但它返回数据大于 10MB 的错误。

如何才能到达 post?有什么我可以做的吗? Noobie swift 程序员。

这是我的代码:

import UIKit
import Parse

class PostImageViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {

@IBOutlet var imageToPost: UIImageView!

@IBOutlet var message: UITextField!

@IBAction func chooseImage(sender: AnyObject) {

    // ... import image
    let image = UIImagePickerController()
    image.delegate = self
    image.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    image.allowsEditing = false

    self.presentViewController(image, animated: true, completion: nil)

}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {

    // ... when user has picked image
    self.dismissViewControllerAnimated(true, completion: nil)

    imageToPost.image = image // set the imageToPost to the image selected in Library


}

@IBAction func postImage(sender: AnyObject) {

    let post = PFObject(className: "Post")

    post["message"] = message.text
    post["userId"] = PFUser.currentUser()!.objectId!


    // save image
    let imageData = UIImagePNGRepresentation(imageToPost.image!)
    let imageFile = PFFile(name: "image.png", data: imageData!)

    post["imageFile"] = imageFile
    post.saveInBackgroundWithBlock { (success, error) -> Void in

        //

        if error == nil {

            print("Success")

        }
    }

}

可能会调整大小并缩小 imageData。更简单的方法可能是:

let imageData = UIImageJPEGRepresentation(imageToPost.image!, 0.1)
let imageFile = PFFile(name: "image.png", data: imageData!)