I'd like to let the user choose a photo from device photo library and then save it to the app's documents folder. Right now I can get the photo from the library but how can I save it in documents folder with its original name? All the answer I found online will require a new name for it. But I don't want to change its extension. Thanks in advance!
you can get image name from this method after selecting the image.
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let fileUrl = info[UIImagePickerController.InfoKey.imageURL] as? URL else { return }
print("Image name", fileUrl.lastPathComponent) // image name
print(fileUrl.pathExtension)
dismiss(animated: true, completion: nil)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.