Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jonathangreco opened this issue Sep 7, 2018 · 10 comments

Comments

@jonathangreco
Copy link

jonathangreco commented Sep 7, 2018

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

@jonathangreco
Copy link
Author

It would be nice if someone can reproduce the bug, to confirm it.

Also, if my issue is not clear please tell me.

This bug is really annoying as there is no workaround yet, I didn't found any.

@jonathangreco
Copy link
Author

jonathangreco commented Oct 31, 2018

Hi is this resolved ?

@zibs
Copy link

zibs commented Nov 10, 2018

I came across this just now too @jonathangreco -- essentially .exists() crashes the android application, but I'm actually able to still base64 it, I just don't check it's existence first, which feels sad.

@jonathangreco
Copy link
Author

jonathangreco commented 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)

@DevAelius
Copy link

_method = () => {
RNFetchBlob.fs.exists('/storage/emulated/0/Download/' + 'download.jpeg')
.then((fileisThere) => {
console.log('status', fileisThere)
fileisThere ?
console.log('ok') :
console.log('!=ok')

  }).catch((err) => {
    console.log(err)
  })

}

@tmaly1980
Copy link

I'm getting crashes with RNFetchBlob.fs.exists as well, and I'm not sure why. Is using stat() the best workaround?

@tmaly1980
Copy link

@DevAelius What is your comment about?

@jonathangreco
Copy link
Author

Since I used stats I was able to make the trick and never crashed. My App is in production and all light are green ;)

What version of react-native do you use ?

@tmaly1980
Copy link

@jonathangreco I'm using RN 0.60.5, though I've finally found my problem (slightly different issue):

#469

@dbilgin
Copy link

dbilgin commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants