Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"File not found" on file that definitely exists #721

Open
Lootwig opened this issue Dec 2, 2024 · 1 comment
Open

"File not found" on file that definitely exists #721

Lootwig opened this issue Dec 2, 2024 · 1 comment
Labels
InputImage Issues related to InputImage

Comments

@Lootwig
Copy link

Lootwig commented Dec 2, 2024

Description

Run the example code on an Android Emulator (requires dependency on the file package).

Outputs true but then throws the following exception when executing the InputImage.fromFile() line:

I/flutter ( 7719): true
E/MLKitImageUtils( 7719): Could not open file: file:///img.jpg
E/MLKitImageUtils( 7719): java.io.FileNotFoundException: /img.jpg: open failed: ENOENT (No such file or directory)
E/MLKitImageUtils( 7719): 	at libcore.io.IoBridge.open(IoBridge.java:574)
E/MLKitImageUtils( 7719): 	at java.io.FileInputStream.<init>(FileInputStream.java:179)
E/MLKitImageUtils( 7719): 	at java.io.FileInputStream.<init>(FileInputStream.java:133)
E/MLKitImageUtils( 7719): 	at android.content.ContentResolver.openInputStream(ContentResolver.java:1526)
E/MLKitImageUtils( 7719): 	at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:2858)
E/MLKitImageUtils( 7719): 	at com.google.mlkit.vision.common.internal.ImageUtils.zza(com.google.mlkit:vision-common@@17.3.0:1)
E/MLKitImageUtils( 7719): 	at com.google.mlkit.vision.common.InputImage.fromFilePath(com.google.mlkit:vision-common@@17.3.0:4)

Note: I am happy to re-word the issue if it's about the MFS, but in that case the complaint would just move to "it is surprisingly difficult to test this package", given that tests can't be run on a host, and there's seemingly no straightforward way to obtain an InputImage from an asset

Example code

import 'package:file/memory.dart';
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';

class Recognizer {
  final fs = MemoryFileSystem();

  Recognizer();

  void r() async {
    final f = fs.file('/img.jpg')..writeAsBytesSync([]);
    print('${f.existsSync()}');
    final r = await TextRecognizer().processImage(InputImage.fromFile(f));
    print('$r');
  }
}

What is the expected result?

An error about the file being empty, or whatever the actual problem is (same error occurs when writing the bytes of an asset file instead of the empty list used in the example)

Did you try our example app?

No

Is it reproducible in the example app?

No

Reproducible in which OS?

Android

Flutter/Dart Version?

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.27.0-1.0.pre.669, on macOS 14.6.1 23G93 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.3)
[✓] VS Code (version 1.95.3)
[✓] VS Code (version 1.85.0-insider)

Plugin Version?

0.14.0

@fbernaly fbernaly added the InputImage Issues related to InputImage label Dec 2, 2024
@Danse117
Copy link

I'm stuck having the same issue, specified my assets in my pubspec but still "File not found". I've tried using the default options but still no output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
InputImage Issues related to InputImage
Projects
None yet
Development

No branches or pull requests

3 participants