Closed YeisonVelez11 closed 4 years ago
const path = uri.replace('file://', '');
The path is correct, but you need to grant read/write permissions :
add in android/app/src/main/AndroidManifest.xml :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Then you need to use AndroidPermissions , so
import {PermissionsAndroid} from 'react-native';
and then define something like this :
requestRWPermissions= async ()=> {
const checkReadExternalStorage = PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
const checkWriteExternalStorage = PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
if (checkReadExternalStorage === PermissionsAndroid.RESULTS.GRANTED && checkWriteExternalStorage === PermissionsAndroid.RESULTS.GRANTED ) {
//alert("You've have read/write permission");
} else {
try {
const grantedRead = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
{
'title': 'FollowUP App required read external storage permission',
'message': 'We required read external storage permission in order to get device location ' +
'Please grant us.'
}
)
const grantedWrite = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
'title': 'FollowUP App required write external storage permission',
'message': 'We required write external storage permission in order to get device location ' +
'Please grant us.'
}
)
if (grantedRead === PermissionsAndroid.RESULTS.GRANTED && grantedWrite === PermissionsAndroid.RESULTS.GRANTED) {
this.takePicture();
} else {
//alert("You don't have read/write permission");
}
} catch (err) {
alert(err)
}
}
};
and takePicture is something like :
takePicture = async () => {
if (this.camera) {
const options = { quality: 0.9, base64: true };
const data = await this.camera.takePictureAsync(options);
const tessOptions = {
whitelist: null,
blacklist: '1234567890\'!"#$%&/()={}[]+*-_:;<>'
};
RNTesseractOcr.recognize(data.uri.replace('file://', ''), 'LANG_ENGLISH', tessOptions)
.then((result) => {
this.setState({ ocrResult: result });
console.log("OCR Result: ", result);
})
.catch((err) => {
console.log("OCR Error: ", err);
})
.done();
}
}
or try after you install it on phone to give manually from file explorer the permissions
Hi @YeisonVelez11, as @mihailpreda commented it is necessary to grant read/write permissions and also remove the substring file://
from your path. You don't have to do this manually anymore since it is handled by the library since v2.
I am using react-native
this is my file generated by (react-native-camera)
file:///data/user/0/com.testproject/cache/Camera/75e0563e-d2c8-47b5-928b-b6d5be8c13c1.jpg