Closed arkivika closed 3 years ago
Is there any solution for this issue or should I move on with a new plugin ?
I think ImagePicker.pickVideo is adding a redundant prefix “file://” at the beginning of the file path. The code below could solve the problem.
File file = await ImagePicker.pickVideo(source: ImageSource.gallery);
String filePath = file.path;
if (filePath.indexOf('file://') == 0)
filePath = filePath.split('file://')[1];
file = File(filePath);
Hi, could you please confirm if this problem still exists with the latest versions on stable or master?
Thanks a lot
I have the same exact problem and only with iOS (android is ok). I tried the fix proposed by @markqq but it does not work. ImagePicker.pickVideo(source: ImageSource.gallery)
does not generate a file. For reference the ImagePicker.pickVideo(source: ImageSource.camera)
works fine in iOS and Android, so the problem is only with picking video from iOS gallery.
Here is my code and the error log
_pickVideoPlus() async {
File file = await ImagePicker.pickVideo(source: ImageSource.gallery);
print('file.path = ' + file.toString());
String filePath = file.path;
print('file.path = ' + filePath);
if (filePath.indexOf('file://') == 0)
filePath = filePath.split('file://')[1];
print('file.path dopo= ' + filePath);
final sizeFile = File(filePath).lengthSync();
print('file.path after = ' + filePath);
if (sizeFile < maxVideoSIzeInBytes) {
_video = File(filePath);
print('printing... size video 1 = ' + _video.lengthSync().toString());
print('printing... size video 2 = ' +
File(_video.resolveSymbolicLinksSync()).lengthSync().toString());
print("exist sync da pick video? " + _video.existsSync().toString());
_videoPlayerController = VideoPlayerController.file(_video)
..initialize().then((_) {
setState(() {});
_videoPlayerController.play();
});
} else {
showDialog(
context: context,
builder: (BuildContext context) => ShowDialogToDismiss(
title: 'Error',
content: 'The size of the video is too big. Your video was ' +
(sizeFile ~/ 1048576).toString() +
' MB.Please upload a video which is less than ' +
maxVideoSizeInMegaBytes.toString() +
' MB in size',
buttonText: 'CLOSE'));
}
}
`2019-10-22 09:02:54.821538+0100 Runner[2166:552419] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"" 2019-10-22 09:02:54.830873+0100 Runner[2166:552338] flutter: file.path = File: '/private/var/mobile/Containers/Data/PluginKitPlugin/C2F6988A-77EE-470A-B1E9-643F834147A5/tmp/trim.81C21145-578E-418F-9187-59EFA15DA124.MOV' 2019-10-22 09:02:54.830934+0100 Runner[2166:552338] flutter: file.path = /private/var/mobile/Containers/Data/PluginKitPlugin/C2F6988A-77EE-470A-B1E9-643F834147A5/tmp/trim.81C21145-578E-418F-9187-59EFA15DA124.MOV 2019-10-22 09:02:54.830990+0100 Runner[2166:552338] flutter: file.path dopo= /private/var/mobile/Containers/Data/PluginKitPlugin/C2F6988A-77EE-470A-B1E9-643F834147A5/tmp/trim.81C21145-578E-418F-9187-59EFA15DA124.MOV 2019-10-22 09:02:54.835093+0100 Runner[2166:552338] [VERBOSE-2:ui_dart_state.cc(148)] Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '/private/var/mobile/Containers/Data/PluginKitPlugin/C2F6988A-77EE-470A-B1E9-643F834147A5/tmp/trim.81C21145-578E-418F-9187-59EFA15DA124.MOV' (OS Error: Operation not permitted, errno = 1)
I found this, if than can help you https://github.com/flutter/flutter/issues/41046
Manu thanks for this. I read through the links but still not sure what to do. Is the plan that I should wait until the next version of the image_picker plugin?
Hav you tried this here to get the coming PR already now? https://github.com/flutter/flutter/issues/41046#issuecomment-538310691
Hi, I have not tried. I am pretty a beginner... I guess I need to put it in the pubspec.yaml file but where should I write it? here is my file
Just replace the line with image_picker
with
image_picker:
git:
url: git://github.com/miguelpruivo/plugins.git
path: packages/image_picker
ref: image_picker-Fix-#41046
I get this error (sorry I feel a bit noob...)
Git error. Command: git clone --mirror git@github.com:miguelpruivo/plugins.git /Users/xxx/Developer/flutter/.pub-cache/git/cache/plugins-xxx Cloning into bare repository '/Users/xxx/Developer/flutter/.pub-cache/git/cache/plugins-xxx'... Host key verification failed. fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Sorry, my fault I correct the above pubspec.
I think that should work now. Please also see https://flutter.dev/docs/development/packages-and-plugins/using-packages
Many thanks, it all works perfectly !
It seems like this issue is already resolved based on the discussion. Let's close it
Hi @arkivika
This is correctly working with the latest image_picker
version 0.6.7+22
, it is getVideo
now instead of pickVideo
which returns the PickedFile
object.
PickedFile doesn't have .exist
properly but it has .path
property which verified file does exist after picking on iOS
void _onImageButtonPressed(ImageSource source, {BuildContext context}) async {
if (_controller != null) {
await _controller.setVolume(0.0);
}
if (isVideo) {
final PickedFile file = await _picker.getVideo(
source: source, maxDuration: const Duration(seconds: 10));
print("File exist? : ${file.path}");
[+18429 ms] flutter: File exist? :
/Users/tahatesser/Library/Developer/CoreSimulator/Devices/959C5334-5E00-420C-BF30-033E4F51150A/data/Containers/Data/Application/B462
AAC1-1913-4263-A7C3-C7549025DA52/tmp/trim.8E09A695-1CB8-4A44-BF03-3AC2D0BD09FB.MOV
Closing as fixed. If you disagree, please write in the comments and I will reopen it. Thank you
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v
and a minimal reproduction of the issue.
Calling file.exists() on the file returned by the ImagePicker.pickVideo() returns false.
flutter doctor -v
```bash > [✓] Flutter (Channel dev, v1.3.13, on Mac OS X 10.14.3 18D109, locale en-FI) > • Flutter version 1.3.13 at /Users/arkivika/Development/flutter > • Framework revision 59ce7d6bff (2 days ago), 2019-03-18 11:20:10 -0700 > • Engine revision e75f6de01f > • Dart version 2.2.1 (build 2.2.1-dev.1.0 None) > > [✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3) > • Android SDK at /Users/arkivika/Library/Android/sdk > • Android NDK location not configured (optional; useful for native profiling support) > • Platform android-28, build-tools 28.0.3 > • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java > • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01) > • All Android licenses accepted. > > [✓] iOS toolchain - develop for iOS devices (Xcode 10.1) > • Xcode at /Applications/Xcode.app/Contents/Developer > • Xcode 10.1, Build version 10B61 > • ios-deploy 1.9.4 > • CocoaPods version 1.5.3 > > [✓] Android Studio (version 3.3) > • Android Studio at /Applications/Android Studio.app/Contents > • Flutter plugin version 33.3.1 > • Dart plugin version 182.5215 > • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01) > > [✓] VS Code (version 1.32.2) > • VS Code at /Applications/Visual Studio Code.app/Contents > • Flutter extension version 2.24.0 > > [✓] Connected device (1 available) > • iPhone 6 Plus (-) • c3e954267f3f2d620b9fe9e95a455fb30aaf651f • ios • iOS 12.1.4 > > • No issues found! ```