jonathanpalma / react-native-tesseract-ocr

Tesseract OCR wrapper for React Native
MIT License
565 stars 172 forks source link

java.io.IOException: Could not create directory at Object.promiseMethodWrapper [as recognize] #89

Closed PingZaiDotTse closed 3 years ago

PingZaiDotTse commented 4 years ago

when after take a picture,the Error appear in the console.

image

image

pkg.json

image

What wrong operation did I do to cause this problem?

thanks

PujanShah22 commented 4 years ago

I was facing same issues. These steps helped me to fix bugs: 1) In Android Folder, open AndroidMenifest file and add android:requestLegacyExternalStorage

<manifest ... >
  <!-- This attribute is "false" by default on apps targeting Android Q. -->
  <application 
      android:requestLegacyExternalStorage="true"
     ... >
    ...
  </application>
</manifest>

2) Check that you have language.traineddata (for example eng.traineddata for English language) in android/app/main/assets/tessdata/ ? if not create assets/tessdata folders. Download your required language's traineddata file from here https://github.com/tesseract-ocr/tessdata and paste in android/app/main/assets/tessdata/

These steps helped me to fix. If it works for you then like my comments. So, others can refer this positively

PingZaiDotTse commented 4 years ago

I was facing same issues. These steps helped me to fix bugs:

  1. In Android Folder, open AndroidMenifest file and add android:requestLegacyExternalStorage
<manifest ... >
  <!-- This attribute is "false" by default on apps targeting Android Q. -->
  <application 
      android:requestLegacyExternalStorage="true"
     ... >
    ...
  </application>
</manifest>
  1. Check that you have language.traineddata (for example eng.traineddata for English language) in android/app/main/assets/tessdata/ ? if not create assets/tessdata folders. Download your required language's traineddata file from here https://github.com/tesseract-ocr/tessdata and paste in android/app/main/assets/tessdata/

These steps helped me to fix. If it works for you then like my comments. So, others can refer this positively

thank you guys, i hava selected other pakege to my project. so i can't verify now. hope it can help the others

abstracted26 commented 4 years ago

I was facing same issues. These steps helped me to fix bugs:

  1. In Android Folder, open AndroidMenifest file and add android:requestLegacyExternalStorage
<manifest ... >
  <!-- This attribute is "false" by default on apps targeting Android Q. -->
  <application 
      android:requestLegacyExternalStorage="true"
     ... >
    ...
  </application>
</manifest>
  1. Check that you have language.traineddata (for example eng.traineddata for English language) in android/app/main/assets/tessdata/ ? if not create assets/tessdata folders. Download your required language's traineddata file from here https://github.com/tesseract-ocr/tessdata and paste in android/app/main/assets/tessdata/

These steps helped me to fix. If it works for you then like my comments. So, others can refer this positively

thank you guys, i hava selected other pakege to my project. so i can't verify now. hope it can help the others

created a folder named assets and then created a folder under assets named tessdata and pasted eng.traineddata there. But the app still shows [Error: java.io.FileNotFoundException: tessdata/eng.traineddata]

Help Please!

PujanShah22 commented 4 years ago

I was facing same issues. These steps helped me to fix bugs:

  1. In Android Folder, open AndroidMenifest file and add android:requestLegacyExternalStorage
<manifest ... >
  <!-- This attribute is "false" by default on apps targeting Android Q. -->
  <application 
      android:requestLegacyExternalStorage="true"
     ... >
    ...
  </application>
</manifest>
  1. Check that you have language.traineddata (for example eng.traineddata for English language) in android/app/main/assets/tessdata/ ? if not create assets/tessdata folders. Download your required language's traineddata file from here https://github.com/tesseract-ocr/tessdata and paste in android/app/main/assets/tessdata/

These steps helped me to fix. If it works for you then like my comments. So, others can refer this positively

thank you guys, i hava selected other pakege to my project. so i can't verify now. hope it can help the others

created a folder named assets and then created a folder under assets named tessdata and pasted eng.traineddata there. But the app still shows [Error: java.io.FileNotFoundException: tessdata/eng.traineddata]

Help Please!

@abstracted26 Can you please post error logs of android studio here? So, I can help you :)

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

vigyanhoon commented 3 years ago

I am getting the same error Possible Unhandled Promise Rejection (id: 0): Error: java.io.IOException: Could not create directory promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2242:45

commitHookEffectListMount@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:19990:38 commitPassiveHookEffects@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:20025:44 invokeGuardedCallbackImpl@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9546:21 invokeGuardedCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9640:42 flushPassiveEffectsImpl@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:22369:36 unstable_runWithPriority@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47583:30 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:22237:36 workLoop@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47528:48 flushWork@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47486:30 _flushCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47026:24 _callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30962:17 callTimers@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:31170:19 callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2765:36 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2497:31 guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2719:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2496:21 callFunctionReturnFlushedQueue@[native code]

Possible Unhandled Promise Rejection (id: 0): Error: java.io.FileNotFoundException: tessdata/eng.traineddata promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2242:45 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:157445:49 commitHookEffectListMount@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:19990:38 commitPassiveHookEffects@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:20025:44 invokeGuardedCallbackImpl@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9546:21 invokeGuardedCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9640:42 flushPassiveEffectsImpl@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:22369:36 unstable_runWithPriority@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47583:30 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:22237:36 workLoop@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47528:48 flushWork@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47486:30 _flushCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:47026:24 _callTimer@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30962:17 callTimers@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:31170:19 callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2765:36 http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2497:31 guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2719:15 callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2496:21 callFunctionReturnFlushedQueue@[native code]

lloytynoja commented 3 years ago

@vigyanhoon

    private void prepareTrainedFilesDirectory() throws IOException {
        Log.d(getName(), "prepare trained files directory");
        File dir = new File(TESS_FILES_PATH);
        if (!dir.exists()) {
            if (!dir.mkdirs()) {
                Log.e(getName(), "Could not create directory, please make sure the app has write permission");
                throw new IOException("Could not create directory");
            }
        }
    }

I went through the java code and found the exception and searched for mkdirs from android documentation, which gave some pointers. I was able to get this to work by adding the parameter and creating directory as described here but additionally I had to allow the storage permission for app by long tap over app icon -> information -> permissions -> allow storage (names probably off as I'm using my phone with Finnish language). But you should get the idea. It probably is possible to add this permission to manifest as well.

One additional thing I noticed was that you should load tess files from tesseract 3.x, not from 4.