I'm using the following condition which doesn't execute for Images (but executes for Videos).
if let imgUrl = info[UIImagePickerControllerReferenceURL] as? URL{
let imgName = imgUrl.lastPathComponent
let documentDirectory = NSTemporaryDirectory()
let localPath = documentDirectory.appending(imgName)
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
let data = UIImageJPEGRepresentation(image, 0.3)! as NSData
//data.write(toFile: localPath, atomically: true)
let photoURL = URL.init(fileURLWithPath: localPath)
let attr: NSDictionary = try! FileManager.default.attributesOfItem(atPath: (photoURL.path)) as NSDictionary
print("file size is :", attr.fileSize(), attr.fileSize()/1024, (attr.fileSize()/1024)/1024)
print(photoURL)
}
I am getting the error:
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “asset.JPG” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/engineering07/Library/Developer/CoreSimulator/Devices/5B35C341-204E-43F0-A2DE-199757E38835/data/Containers/Data/Application/43182136-8C82-4385-99A7-F0F30B30A785/tmp/asset.JPG, NSUnderlyingError=0x608000246360 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
I am not able to understand what's wrong here or what's missing here. Please help me understand how to correct it. Thank you.