Failed to find configured root that contains
Billmike opened this issue · 12 comments
Hi. I'm running into this error when trying to make use of your Library. I combining this library with react-native-document-picker. I have in my android/app/src/main/res/xml
file the following code:
<?xml version='1.0' encoding='utf-8'?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="files" path="/" />
<external-files-path name="external_files" path="" />
<external-path name="external" path="." />
<cache-path name="cache" path="/" />
</paths>
Also, in my AndroidManifest.xml
file, I have:
<provider
android:name="com.vinzscam.reactnativefileviewer.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_viewer_provider_paths"
/>
</provider>
Library is linked as directed in the docs. In my code, after getting the response object returned by react-native-document-picker, I am passing the uri as an argument to the open method:
const resFile = await documentPicker(['images'], {maxWidth: 250}) // This is a utility method that abstracts certain implementations, but functionality is same as regular documentPicker
if (resFile) {
FileViewer.open(resFile.uri)
.then(() => {
//do something awesome here
})
.catch(error => {
console.log(error) // This bit prints out the `Failed to find configured root that contains` errors
})
}
React Native version: 0.59.9
React Native File Viewer version: 2.0.2
you need to remove the filePath.replace('file://', '')
Where is the filePath.replace('file://', '')
located?
Same problem faced :
Want to read pdf from Url 'http://www.africau.edu/images/default/sample.pdf' but getting error
Error: Failed to find configured root that contains /http:/www.africau.edu/images/default/sample.pdf
Hi @Billmike! Have you tried to follow the Automatic Installation procedure by running react-native link react-native-file-viewer
instead of manually change your files?
Hello. Also getting this error on android. however works fine on ios
@BertoGz check if the filepath contains the string file://, if so, delete it, and use this new filepath as argument
@arcollector yes. when i log the uri that I am giving to the function it shows up with "file:///storage/"
but when i check the Error in the console, the uri is this format "/file:/storage"
why does it change?
Hi, the issue should now be resolved in version 2.1.2
Hi I am also facing same issue whem opening an url please tell me how to resolve the problem
hey @vinzscam hope you are fine, I'm still facing the same issue, can you or anyone here help me to solve this issue.
My Packages Version:
react-native-file-viewer": "^2.1.5"
"react": "17.0.2"
"react-native": "0.66.0"
Same problem faced : Want to read pdf from Url 'http://www.africau.edu/images/default/sample.pdf' but getting error
Error: Failed to find configured root that contains /http:/www.africau.edu/images/default/sample.pdf
Did you find any solution later? I'm also trying to do the same thing.
Hi , I was facing same issue .
Solution :
I used react-native-fs to save this file locally in a specific path and then checked if that path avaible . If path exists, then I chose that file by adding the prefix "file://" to path.
RNFS.downloadFile({
fromUrl: 'https://www.africau.edu/images/default/sample.pdf',
toFile: ${RNFS.DocumentDirectoryPath}/sample.pdf
,
}).promise.then((r) => {
this.setState({ isDone: true })
});
}
const path = ${RNFS.DocumentDirectoryPath}/sample.pdf
;
const fileExists = await RNFS.exists(path);
if (fileExists) {
//we already have it in local storage
return {
url: "file://" + path,
};