gpt4 book ai didi

ios - Swift 2、Xcode 7.2 'NSInternalInconsistencyException

转载 作者:行者123 更新时间:2023-11-30 13:36:47 27 4
gpt4 key购买 nike

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 数据库,我试图将图像发布到我的数据库,但它返回数据大于 10MB 的错误。

我怎样才能让它发布?有什么我可以做的吗?菜鸟快速程序员。

这是我的代码:

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

关于ios - Swift 2、Xcode 7.2 'NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35977979/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com