Error: Invalid Filesystem URI

Hello, i’m trying download a file using:

FileSystem.createDownloadResumable("http://remote-uri.com", `${FileSystem.documentDirectory}my_file.ext`)

In IOS it works very well, but in android i got this error:

 Invalid Filesystem URI 'file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540my_user%252Fmy-react-native-app/my_file.ext', make sure it's in the app's scope.

What can i do?


Environment:

"expo": "^20.0.0",
"react": "16.0.0-alpha.12",
"react-native": "https://github.com/expo/react-native/archive/sdk-20.0.0.tar.gz",

Hey, I’m experiencing the same issue. It seems like there’s something wrong with the path that’s generated for android. Not sure how to approach it but I know it occurs for more than just downloading.

simple example that produces the same error on android but works on iOS:

async componentWillMount () {
    try {
      let documentDirectory = await FileSystem.readDirectoryAsync(FileSystem.documentDirectory)
      console.log('document: ', documentDirectory)
    } catch (err) {
      console.error(err)
    }
  }

I found a solution. I create a folder inside document directory and after it works well.

ensureFolderExists () {
    const path = `${FileSystem.documentDirectory}MyFolder`
    return FileSystem.getInfoAsync(path).then(({exists}) => {
      if (!exists) {
        return FileSystem.makeDirectoryAsync(path)
      } else {
        return Promise.resolve(true)
      }
    })
  }

ensureFolderExists().then(() => {
  FileSystem.createDownloadResumable("http://remote-uri.com", `${FileSystem.documentDirectory}MyFolder/my_file.ext`).downloadAsync()
})
1 Like

can you show me how to do it in my code ?

saveDbData = async () => {
    const { data, isLoaded } = this.state;
    for (let i = 0; i < data.length; i++) {
      const mediaData = data[i];
      const dbResult = await insertPlace(
        mediaData.artist,
        mediaData.image,
        mediaData.title,
        mediaData.url
      );
      const { uri } = await FileSystem.getInfoAsync(
        `${FileSystem.documentDirectory}SQLite/${'places.db'}`
    )
     console.log("THIS IS PATH OF THE DB",uri)// WHEN U WANT SEE THE PATH OF THE DB FILE 

    }
     
    const fetchawesome = await fetchPlaces();
     console.log("THIS MY DB :",fetchawesome) //WHEN U WANT PRINT THE CONTENT OF THE DB
    
  };