Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native <Image> not loading image from sdcard in android

I am trying to load image from external sdcard after I take photo from camera in React native image component as following, but it is not rendering in android. I even checked if there is image missing at that location, but that's not the problem. But it works well in case of iOS to load image from location after taking photo from camera.

 <Image source={{uri:'/storage/emulated/0/Pictures/image-0ea0d714-9469-432b-8869-b6637be2be10.jpg'}} style={{height:200, width:200}} />

Here's my permission list in AndroidManifest.xml

<!-- For Image picker start -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
like image 651
Rajan Twanabashu Avatar asked Jun 17 '16 10:06

Rajan Twanabashu


1 Answers

Just had this issue, solved it by prepending the filepaths with file://

So, instead of:

 <Image source={{uri:'/storage/emulated/0/Pictures/myImage.jpg'}} style={myImageStyle} />

Use:

 <Image source={{uri:'file:///storage/emulated/0/Pictures/myImage.jpg'}} style={myImageStyle} />

Note the 3 consecutive slashes as opposed to just two as suggested by @Cherniv.

like image 183
DSquare Avatar answered Oct 05 '22 21:10

DSquare