12

I have succesfully been able to take a photo inside my app and store it on the phone, but how do I display it?

I tried this static approach but it does not work (Yes the image is there :) )

 <Image width={40} height={40} source={{uri: '/storage/emulated/0/DCIM/IMG_20161201_125218.jpg'}} /> 
7
  • Are you using a library to take the picture? you should be able to get the data returned from that. Otherwise, what about the Camera Roll API? Commented Dec 1, 2016 at 13:35
  • The library im using just returns the path to the file. Commented Dec 1, 2016 at 14:02
  • What library is it? Commented Dec 1, 2016 at 14:06
  • react-native-camera Commented Dec 2, 2016 at 19:44
  • what captureTarget are you using? it might help to post your configuration. github.com/lwansbrough/react-native-camera#capturetarget Commented Dec 2, 2016 at 20:13

3 Answers 3

32

Even I faced this issues and got it resolved. You have to prepend the the file path with file:// (mind the double /).

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

Here's a reference!

I hope this helps :)

Sign up to request clarification or add additional context in comments.

4 Comments

It doesn't work for me file:///storage/emulated/0/appiwell/image/qkpOyUaRla.jpg
It does not help me
@TuanNguyen could you find a solution? adding file:// works only on simulator, on real device it does not work
@Which device for you? Simply, pick uri of file and add file:// if OS is android. Dont add for ios.
1
 <Image source = {{uri: "file:///storage/emulated/0/appiwell/image/qkpOyUaRla.jpg", width: responsiveWidth(100), height: responsiveHeight(100)}}/> 

Notice, should set width, height inside {uri, width, height}. Width, height in style maybe didn't work.

responsiveWidth, responsiveHeight here https://www.npmjs.com/package/react-native-responsive-dimensions

Comments

1

We should get 'READ_EXTERNAL_STORAGE' Permission


  • Import

// import import { PermissionsAndroid } from "react-native"; 
  • Function to request permission

// function to request permission requestStoragePermission = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, { title: "Permission title", message: "Permission message", buttonNeutral: "Ask Me Later", buttonNegative: "Cancel", buttonPositive: "OK", } ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log("You can use the EXTERNAL_STORAGE"); } else { console.log("EXTERNAL_STORAGE permission denied"); } } catch (err) { console.warn(err); } }; 
  • Call the above Function

<Button title="request permissions" onPress={this.requestStoragePermission} /> 

Click this for reactnative android permissions docs

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.