How can I get the name of video file selected from Camera roll or any other album in UIImagePickerController
's delegate method ?
I'm able to get the name of image but if using same in video it's returning nil
.
How can I get the name of video file selected from Camera roll or any other album in UIImagePickerController
's delegate method ?
I'm able to get the name of image but if using same in video it's returning nil
.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if (![mediaType isEqualToString:(NSString *)kUTTypeMovie])
return;
mediaURl = [info objectForKey:UIImagePickerControllerMediaURL];
//NSLog(@"mediaURL %@",mediaURl);
moviePath = mediaURl.absoluteString;
// NSLog(@"moviePath %@",moviePath);
tempFilePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
NSLog(@"filepath %@",tempFilePath);
//if you want only file name
NSArray *ar = [tempFilePath componentsSeparatedByString:@"/"];
NSString *filename = [[ar lastObject] uppercaseString];
NSLog(@"filename %@",filename);
}
Let me know if you have any issues
I know this thread is super old but i thought if someone finds it, here is a working answer in swift:
func fileName(for infoDict: [String : Any]) -> String? {
guard let referenceURL = infoDict[UIImagePickerControllerReferenceURL] as? URL else { return nil }
let result = PHAsset.fetchAssets(withALAssetURLs: [referenceURL], options: nil)
guard let asset = result.firstObject else { return nil }
let firstResource = PHAssetResource.assetResources(for: asset).first
return firstResource?.originalFilename ?? asset.value(forKey: "filename") as? String
}
Swift 4 or later Working on My Side for the captured image
Use :
imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
let fileName = FileInfo.getMediaName(info: info)
}
class : pleas put the method info[:]
class FileInfo {
// Return Media name
static func getMediaName(info:[String : Any]) -> String {
if let asset = info[UIImagePickerControllerPHAsset] as? PHAsset {
let assetResources = PHAssetResource.assetResources(for: asset)
let firstObj = assetResources.first?.originalFilename as! NSString
print(firstObj)
return firstObj
}
}
}
// IMG_02256.jpeg