我想從文檔路徑加載圖像,在我的情況下顯示爲file:///var/mobile/Containers/Data/Application/AE7B9E43-E92D-4029-AE8D-4500CB61C15D/Documents/uploadImage.jpg
。我將如何獲取該圖像,以便可以使用POST調用發送該圖像?我正在保存imagePickerController
的圖片。這是我必須保存圖像的代碼...從UIImagePickerController保存圖像抓取圖像?
let fileDirectory : NSURL = {
return try! FileManager.default.url(for: .documentDirectory , in: .userDomainMask , appropriateFor: nil, create: true)
}() as NSURL
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let imagePath = fileDirectory.appendingPathComponent("uploadImage.jpg")
guard let imageData = UIImageJPEGRepresentation(image, 0.5) else {
// handle failed conversion
presentAlert(title: "Error", message: "Image Failure")
print("jpg error")
return
}
try! imageData.write(to: imagePath!
print("Image Path: \(imagePath!)")