0
我無法保存捕獲的圖像,並使用Parse將其發送到我的mongodb。我不確定我的錯誤與什麼有關。我絕對有使用我的imagePickerController正確的圖像捕捉部分。將圖像上傳到解析失敗
這裏是我的代碼:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
print("Did finish picking media. Image \(image)")
let imageData = UIImagePNGRepresentation(image)
let imageFile = PFFile(name:"image.png", data:imageData!)
let pohto_object = PFObject(className: "UserPhoto")
pohto_object["imageName"] = "My trip to Hawaii!"
pohto_object["imageFile"] = imageFile
pohto_object.saveInBackground() { (success, error) -> Void in
if error == nil {
print("Saved in server")
} else {
print("did not save because: \(error!)")
}
}
print ("the object is \(pohto_object)")
} else {
print("Did finish picking media. Image is nil")
}
dismiss(animated: true)
}
這是我在控制檯輸出:
Did finish picking media. Image <UIImage: 0x17468ac30> size {3024, 4032} orientation 3 scale 1.000000
libc++abi.dylib: terminating with uncaught exception of type NSException
注意UIImagePNGRepresentation將導致未壓縮的數據(太多的數據上傳),它也將放棄您的圖像方向。我推薦使用UIImageJPEGRepresentation –
這解決了我的問題!謝謝! –