Skip to content

Commit 9451206

Browse files
Merge pull request #1875 from potch8228/ios_bigfile_load
[iOS] Use NSFileManager to copy tmp data (from using bare NSData)
2 parents 8950fd0 + b7e8e6e commit 9451206

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 10.3.5
2+
## iOS
3+
- Fixed an error when loading large files (>= 2GB~).
4+
15
## 10.3.4
26
## Android
37
- Detect HEIC and HEIF extensions as valid image

ios/file_picker/Sources/file_picker/FilePickerPlugin.m

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
565565
[result.itemProvider loadFileRepresentationForTypeIdentifier:typeIdentifier completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
566566
@autoreleasepool {
567567
if (error != nil || url == nil) {
568-
[errors addObject:[NSString stringWithFormat:@"Failed to load image at index %ld: %@",
568+
[errors addObject:[NSString stringWithFormat:@"Failed to load image/video at index %ld: %@",
569569
(long)index, error ? error.localizedDescription : @"Unknown error"]];
570570
dispatch_group_leave(self->_group);
571571
return;
@@ -583,26 +583,17 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
583583

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

588-
if (loadError || !imageData) {
589-
[errors addObject:[NSString stringWithFormat:@"Failed to load image data at index %ld: %@",
590-
(long)index, loadError.localizedDescription ?: @"Unknown error"]];
587+
// Write to destination
588+
if ([[NSFileManager defaultManager] copyItemAtURL:url toURL:destinationUrl error:&loadError]) {
589+
[urls addObject:destinationUrl];
591590
} else {
592-
// Write to destination
593-
if ([imageData writeToURL:destinationUrl options:NSDataWritingAtomic error:&loadError]) {
594-
[urls addObject:destinationUrl];
595-
} else {
596-
[errors addObject:[NSString stringWithFormat:@"Failed to save image at index %ld: %@",
597-
(long)index, loadError.localizedDescription]];
598-
}
591+
[errors addObject:[NSString stringWithFormat:@"Failed to save image/video at index %ld: %@",
592+
(long)index, loadError.localizedDescription]];
599593
}
600594

601-
// Clean up
602-
imageData = nil;
603-
604595
} @catch (NSException *exception) {
605-
[errors addObject:[NSString stringWithFormat:@"Exception processing image at index %ld: %@",
596+
[errors addObject:[NSString stringWithFormat:@"Exception processing image/video at index %ld: %@",
606597
(long)index, exception.description]];
607598
}
608599

@@ -642,7 +633,7 @@ -(void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPicke
642633
} else {
643634
// Only if all images failed, return an error
644635
self->_result([FlutterError errorWithCode:@"file_picker_error"
645-
message:@"Failed to process any images"
636+
message:@"Failed to process any images/video"
646637
details:[errors componentsJoinedByString:@"\n"]]);
647638
}
648639
self->_result = nil;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
33
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
44
repository: https://github.com/miguelpruivo/flutter_file_picker
55
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
6-
version: 10.3.4
6+
version: 10.3.5
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)