question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RNFetchBlob.fs.exists crashes if the file not exist in the gallery (content://) on android

See original GitHub issue

Hi

I’ve an issue about the RNFetchBlob.fs.exists() method.

Context :

  • I’ve an app that record some videos
  • this app stores recorded video using the CameraRoll component.
  • Videos are stored in the gallery (content://media/external/video/media/296)

I’ve tested two things :

  • The video exist in the gallery
  • The video does not exist (remove manually by the user)

The code :

async componentDidMount() {
    const {scene} = this.props;
// scene.film is the uri like content://media/external/video/media/296 (android only at the moment)
    if (scene.film) {
      RNFetchBlob.fs.exists(scene.film)
        .then((exist) => {
          console.log(`file ${exist ? '' : 'not'} exists`)
        })
        .catch((err) => { console.log(err) });

      this.setState({jsx: this.renderFilm(scene)});
    } else {
      this.setState({jsx: this.renderImage()});
    }
  }

Version:

"react-native": "0.56.0",
"rn-fetch-blob": "^0.10.12"

The issue

If the file exist, everything works and console log print :

capture d ecran 2018-09-07 a 09 36 12

If the file has been removed the app crashes and shutdown. This behaviour have been tested on android 7.0, API 24 the device is : SM-T580

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

1reaction
jonathangrecocommented, Nov 26, 2018

@zibs Thanks I still have this issue now and I just use an ugly workaround like this :

// if it's not exist, catch method will know about it :)
  await RNFS.stat(item.uri).then((stat) => {
        // Yolooooooooooooo
      })
        .catch(() => {
          this.doSomthingfalse);
        });

Well like you see here even RNFS can’t make a proper exist method (it’s not handle the content:// return always false)

0reactions
dbilgincommented, Oct 23, 2019

Using stat() fails to return the correct value for content: files on android. @tmaly1980’s fix seems like it would fix this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Read files function is crashing in RNFetchBlob in react native ...
I got it working by changing the download directory path. It was not working due to permissions issue.
Read more >
How to use the rn-fetch-blob.fs function in rn-fetch-blob | Snyk
rn-fetch-blob. A module provides upload, download, and files access API. Supports file stream read/write for process large files.
Read more >
rn-fetch-blob - npm
A module provides upload, download, and files access API. Supports file stream read/write for process large files.. Latest version: 0.12.0, ...
Read more >
Use Filesystem - let's read and write the file by react-native-fs ...
(not available on Android); ExternalDirectoryPath: absolute path of External files, shared directory. (not available on iOS); ExternalStorageDirectoryPath: ...
Read more >
How to access file systems with React Native - LogRocket Blog
Learn the fundamentals of react-native-fs, a library that allows ... is a minor flaw: what if the client wants to edit an existing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found