androidreact-nativereact-native-camera

Convert content:// URI to actual path for Android using React-Native


I am trying to upload images from cameraRoll. But the cameraRoll component returns a content:// URI, rather than an actual file path.

For uploading the image I need a file path, is there any way to convert a content:// URI to a file URI?

Example content URI:

content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FAndroid%2Fdata%2Fcom.miui.gallery%2Fcache%2FSecurityShare%2L78963157412.jpg

Solution

  • I took the function submitted by @Madhukar Hebbar and made it into a React Native Node Module.

    You can find it here: react-native-get-real-path

    Thus to achieve what you want, you can use the above module in conjunction with react-native-fs

    You can then do something like this when you want to upload the selected image from Camera Roll:

    RNGRP.getRealPathFromURI(this.state.selectedImageUri).then(path =>
      RNFS.readFile(path, 'base64').then(imageBase64 =>
        this.props.actions.sendImageAsBase64(imageBase64)
      )
    )