Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 10.3.5
## iOS
- Fixed an error when loading large files (>= 2GB~).

## 10.3.4
## Android
- Detect HEIC and HEIF extensions as valid image
Expand Down
25 changes: 8 additions & 17 deletions ios/file_picker/Sources/file_picker/FilePickerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
[result.itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
@autoreleasepool {
if (error != nil || url == nil) {
[errors addObject:[NSString stringWithFormat:@"Failed to load image at index %ld: %@",
[errors addObject:[NSString stringWithFormat:@"Failed to load image/video at index %ld: %@",
(long)index, error ? error.localizedDescription : @"Unknown error"]];
dispatch_group_leave(self->_group);
return;
Expand All @@ -583,26 +583,17 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke

// Load image data with options to reduce memory usage
NSError *loadError = nil;
NSData *imageData = [NSData dataWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&loadError];

if (loadError || !imageData) {
[errors addObject:[NSString stringWithFormat:@"Failed to load image data at index %ld: %@",
(long)index, loadError.localizedDescription ?: @"Unknown error"]];
// Write to destination
if ([[NSFileManager defaultManager] copyItemAtURL:url toURL:destinationUrl error:&loadError]) {
[urls addObject:destinationUrl];
} else {
// Write to destination
if ([imageData writeToURL:destinationUrl options:NSDataWritingAtomic error:&loadError]) {
[urls addObject:destinationUrl];
} else {
[errors addObject:[NSString stringWithFormat:@"Failed to save image at index %ld: %@",
(long)index, loadError.localizedDescription]];
}
[errors addObject:[NSString stringWithFormat:@"Failed to save image/video at index %ld: %@",
(long)index, loadError.localizedDescription]];
}

// Clean up
imageData = nil;

} @catch (NSException *exception) {
[errors addObject:[NSString stringWithFormat:@"Exception processing image at index %ld: %@",
[errors addObject:[NSString stringWithFormat:@"Exception processing image/video at index %ld: %@",
(long)index, exception.description]];
}

Expand Down Expand Up @@ -642,7 +633,7 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
} else {
// Only if all images failed, return an error
self->_result([FlutterError errorWithCode:@"file_picker_error"
message:@"Failed to process any images"
message:@"Failed to process any images/video"
details:[errors componentsJoinedByString:@"\n"]]);
}
self->_result = nil;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 10.3.4
version: 10.3.5

dependencies:
flutter:
Expand Down