Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 0991498

Browse files
author
Miguel Ruivo
committed
adds error handler when caching a video file from the picker
1 parent a8cd20f commit 0991498

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

packages/image_picker/ios/Classes/ImagePickerPlugin.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,24 @@ - (void)imagePickerController:(UIImagePickerController *)picker
247247
[NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:fileName]];
248248

249249
if ([[NSFileManager defaultManager] isReadableFileAtPath:[videoURL path]]) {
250-
[[NSFileManager defaultManager] copyItemAtURL:videoURL toURL:destination error:nil];
250+
NSError *error;
251+
if (![[videoURL path] isEqualToString:[destination path]]) {
252+
[[NSFileManager defaultManager] copyItemAtURL:videoURL toURL:destination error:&error];
253+
254+
if (error) {
255+
self.result([FlutterError errorWithCode:@"flutter_image_picker_copy_video_error"
256+
message:@"Could not cache the video file."
257+
details:nil]);
258+
self.result = nil;
259+
return;
260+
}
261+
}
251262
videoURL = destination;
252263
}
253264
}
254265
self.result(videoURL.path);
255266
self.result = nil;
267+
256268
} else {
257269
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
258270
if (image == nil) {

0 commit comments

Comments
 (0)