Swift 2, Xcode 7.2 'NSInternalInconsistencyException

LizG
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

Using www.heroku.com as an alternate parse.com. It uses MonoLab database and I am trying to post an image to my database but it is returning the error that data is larger than 10MB.

How can I get it to post? Is there something I can do? Noobie swift programmer.

Here is my code:

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")

        }
    }

}
Allen

Probably resize and have the imageData smaller. A simpler approach could be:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

‘NSInternalInconsistencyException’ when running UITesting with Xcode 7

"no such module" on Xcode 7 beta 2

Xcode 7 beta 5, Swift 2: UITableViewCell's subviews are not added to the contentView at runtime

Parse signup error with swift 2 (xcode 7 beta 5)

Xcode 7 beta 5 Swift 2 redundant conformance to protocol error

Alamofire Swift 2 - cannot submit for beta testing (Xcode 7 GM)

UIScreen.mainScreen().nativeBounds.height not working using Xcode 7/Swift 2, Target iOS7

Xcode 7 does not show function callers for swift 2

Is it safe to upgrade to Xcode 7.1 while writing a project using Xcode 7 and Swift 2

Xcode 7 Swift 2 impossible to instantiate UIViewController subclass of generic UITableViewController

Is it possible to compile Swift 2 code in Xcode 7 and run it on an iOS 11.1 iPhone 6?

Swift and XCode 7 beta 2 are not displaying the metadata of the songs playing

TouchID with Xcode 7, Swift 2

Error when trying to play video in Xcode 7 / Swift 2

Playing audio in Xcode 7 / Swift 2 Not Working

Swift 2 Playground(Xcode 7 Beta 4) - Multiple types in an array only work when UIKit imported?

Unit Testing Core Data in XCode 7 Beta/Swift 2

If string contains statement - Swift 2 Xcode 7

PromiseKit doesn't compile with Swift 2 and Xcode 7

Gmail API iOS in Xcode 7, Swift 2

SKCropNode not working properly in Xcode 7 + Swift 2

Encode JSON to Xcode 7 with Swift 2 and PHP

Swift 2 + Xcode 7: Sound playing when wrong button is pressed

Populating UITableView with JSON data from youtube videos in Swift 2 and Xcode 7

Random generator based off NStimer Xcode 7 swift 2

Building my first game in XCODE 7(swift 2)-CGPOINTMAKE?

Displaying CLLocation in label Xcode 7 Swift 2

How to create an array of images (swift2, xcode7)

Can't get SWRevealViewController working (Swift 2, Xcode 7)