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")
}
}
}
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.
Comments