React-native-fs: for existed file 'content://' exists returns false

Created on 3 Mar 2018  路  17Comments  路  Source: itinance/react-native-fs

I have image file (obtained by using device camera) with following uri
content://media/external/images/media/331
using RNFS.exists.then returns false while file is exists.
how to fix this?

enhancement feature-request

All 17 comments

same here.

The "content://"-scheme is currently not supported. I suppose it is android related right?
We definitely should add support for it.

@itinance yes, in my case it was returning from react-native-image-picker (https://github.com/react-community/react-native-image-picker) on android.

Also ran into this issue on Android when using react-native-document-picker (https://github.com/Elyx0/react-native-document-picker)

Hi did you found any workaround waiting this feature ?

Any workaround on that one?

@llaine Use RNFS.stat should do the trick.

@jonathangreco thank's for your answer. I'm actually trying to use copyFileAssets which throw me an error Error: Asset 'content://media/external/images/media/xx' could not be opened

@itinance Hi, is this issue worth to be a top priority ? Because for as long as I recall, neither React-native-fs nor RNFetchBlob have a functionnal exist method for content:// or asset-library://

@llaine In fact if you try to RNFS.stata medias in your content:// and it not exist, you'll be able to do your stuff in the catch

@jonathangreco The RNFS.stat is throwing the exception. Is there any way to use copyFileAssets on android ?

@llaine of course it throws an exception. It's the whole point of this workaround. Catch it and do what you need to do :)

Here's a workaround until we get native support:

await Promise.all(arrayOfFilesWithContentUris.map(async (file) => {
  const file = await RNFS.stat(file.uri);
  console.log(file.originalFilepath);
  // will now output a regular file url, compatible with other functions, e.g.:
  // RNFS.unlink(file.originalFilepath);
}));

@scarlac thank you, the workaround made it for me 馃憤

@scarlac It's not working for me

07-07 16:14:53.413  5404  7076 I ReactNativeJS: fs stat failed on: content://com.google.android.apps.photos.contentprovider/0/2/mediakey%3A%2Flocal%253A87ecd038-4f96-4c8e-aaf7-4520ad3a6b2c/ORIGINAL/NONE/508284454
07-07 16:14:53.414  5404  7076 I ReactNativeJS: { [Error: Error not specified.]
07-07 16:14:53.414  5404  7076 I ReactNativeJS:   framesToPop: 1,
07-07 16:14:53.414  5404  7076 I ReactNativeJS:   nativeStackAndroid: [],
07-07 16:14:53.414  5404  7076 I ReactNativeJS:   userInfo: null,
07-07 16:14:53.414  5404  7076 I ReactNativeJS:   code: 'EUNSPECIFIED' }
 RNFS.stat(fileUri).then(fileStat => {

});

It just crashes if I try to share image from Photos app, e.g. this one: 'content://com.google.android.apps.photos.contentprovider/1/1/mediakey%3A%2Flocal%253Af752e9f9-7259-4b0a-8ed7-0c8e30f46730/REQUIRE_ORIGINAL/NONE/88846342'

2019-10-18 14:11:30.989 13134-13231/? W/System.err: java.lang.NullPointerException
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at java.io.File.<init>(File.java:283)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at com.rnfs.RNFSManager.stat(RNFSManager.java:626)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:371)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:150)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at android.os.Looper.loop(Looper.java:193)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
2019-10-18 14:11:30.989 13134-13231/? W/System.err:     at java.lang.Thread.run(Thread.java:764)

any chance this is going to be supported? Seems silly to not support content:// for android on a cross-platform architecture

Was this page helpful?
0 / 5 - 0 ratings