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的错误。
我如何将其发布?有什么我可以做的吗?Noobie快速程序员。
这是我的代码:
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!)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句