Skip to content

[image_picker] "No such file or directory" when calling getImage if cache dir does not exist #84251

@Roboroads

Description

@Roboroads

Steps to Reproduce

  1. Install plugin v0.8.0+3 and path_provider flutter pub add image_picker path_provider
  2. Add basic example for android (using both camera or gallery)
  3. Add the following before getImage is called:
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';

// ...

final cacheDir = await getTemporaryDirectory();
if (cacheDir.existsSync()) {
  cacheDir.deleteSync(recursive: true);
}
  1. Run the app on an actual device (I don't run emulators, idk if this is also an emulator problem)
  2. Try to pick a picture with the plugin

Expected results:
Camera opening, plugin re-creates cache director (like it did in 0.7)

Actual results:
java.io.IOException

Logs
[+1079 ms] E/MethodChannel#plugins.flutter.io/image_picker(14828): Failed to handle method call
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828): java.lang.RuntimeException: java.io.IOException: No such file or directory
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugins.imagepicker.ImagePickerDelegate.createTemporaryWritableFile(ImagePickerDelegate.java:385)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugins.imagepicker.ImagePickerDelegate.createTemporaryWritableImageFile(ImagePickerDelegate.java:371)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugins.imagepicker.ImagePickerDelegate.launchTakeImageWithCameraIntent(ImagePickerDelegate.java:360)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugins.imagepicker.ImagePickerDelegate.takeImageWithCamera(ImagePickerDelegate.java:337)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugins.imagepicker.ImagePickerPlugin.onMethodCall(ImagePickerPlugin.java:299)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at android.os.MessageQueue.nativePollOnce(Native Method)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at android.os.MessageQueue.next(MessageQueue.java:336)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at android.os.Looper.loop(Looper.java:174)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at android.app.ActivityThread.main(ActivityThread.java:7682)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at java.lang.reflect.Method.invoke(Native Method)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828): Caused by: java.io.IOException: No such file or directory
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at java.io.UnixFileSystem.createFileExclusively0(Native Method)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at java.io.File.createTempFile(File.java:2044)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      at io.flutter.plugins.imagepicker.ImagePickerDelegate.createTemporaryWritableFile(ImagePickerDelegate.java:383)
[        ] E/MethodChannel#plugins.flutter.io/image_picker(14828):      ... 14 more

-
[✓] Flutter (Channel unknown, 2.0.6, on Linux, locale en_US.UTF-8)
    • Flutter version 2.0.6 at /home/rsc31870/flutter
    • Framework revision 1d9032c7e1 (6 weeks ago), 2021-04-29 17:37:58 -0700
    • Engine revision 05e680e202
    • Dart version 2.12.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /home/rsc31870/Android/Sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /usr/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (2 available)
    • ONEPLUS A6013 (mobile) • 192.168.178.249:5556 • android-arm64  • Android 10 (API 29)
    • Chrome (web)           • chrome               • web-javascript • Google Chrome 91.0.4472.77

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 2.2Found to occur in 2.2found in release: 2.3Found to occur in 2.3has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: image_pickerThe Image Picker plugin.packageflutter/packages repository. See also p: labels.platform-androidAndroid applications specifically

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions