0

Usually, it is easier for me to do this with fetch, but this package does not use fetch. I read other questions similar to mine and here is my attempt in trying to do it:

SelectPhoto = () =>{
ImagePicker.openPicker({
}).then((imgResponse) => {
  console.log(imgResponse.path); <-- Trying to access the path
});
}

I keep getting undefined and here are my console log results:

0:{size: 745660, mime: "image/jpeg", height: 2960, width: 1440, path: "file:///storage/emulated/0/DCIM/Screenshots/Screenshot_20180617-173313.jpg"} length:1

Can anyone help me out with this? Thank you so much!

Laney Williams
  • 573
  • 3
  • 13
  • 34
  • though I don't know for sure: 1.) use ```imgResponse[0].path```? or 2.) is path protected from being read in the first place? – Sebastian Rothbucher Jun 18 '18 at 18:29
  • Ok this worked. Also, I don't think so because it tells me I can do it from this package: https://www.npmjs.com/package/react-native-customized-image-picker. Now all I need to do is figure out how to change the state to that path. @SebastianRothbucher – Laney Williams Jun 18 '18 at 18:41

1 Answers1

1

It looks like you're using react-native-customized-image-picker.

According to their docs and your console.log output, you can get the path and set it to the state as follows:

import React from 'react'
import ImagePicker from 'react-native-customized-image-picker'

class App extends React.Component {
  constructor (props) {
    super(props)

    this.state = { path: null }
    this.handleClick = this.handleClick.bind(this)
  }

  handleClick () {
    ImagePicker.openPicker({}).then(image => {
      const path = image[0].path

      this.setState({ path })
    })
  }

  render () {
    return <div onClick={this.handleClick}>Select image</div>
  }
}
Jordan Enev
  • 16,904
  • 3
  • 42
  • 67