javierrunning / react-native-cloudinary

MIT License
7 stars 8 forks source link

Can't read property config of undefined #7

Closed kaiyes closed 6 years ago

kaiyes commented 6 years ago

screenshot 2017-09-26 11 30 00

kaiyes commented 6 years ago

I did a react-native link react-native-cloudinary . after that, checked in xcode and library seems to have connected. Do I need to do anything else ? screenshot 2017-09-26 11 32 53

kaiyes commented 6 years ago

Added Alomfire git sub module in Ios folder, as well as the cloudinary sdk. As a result, app stopped working all together. However, was able to use react-native-image-crop and fetch. Here is the code. Hopefully it helps someone.


    data.append('name', 'testName')
    data.append('upload_preset', 'xxx')
    data.append('file', {
      uri: image.path,
      type: 'image/jpeg', 
      name: 'testPhotoName'
    })
    fetch(
      `https://api.cloudinary.com/v1_1/xxx/image/upload`,
      {
        method: 'post',
        body: data
      }
    ).then(res => {
      console.log(res)
    })```
oferRounds commented 6 years ago

@kaiyes facing the same issue, did you find a solution?

oferRounds commented 6 years ago

@kaiyes what is data? and what does the name key refer to?

kaiyes commented 6 years ago

@oferRounds I used this package instead. https://github.com/ivpusic/react-native-image-crop-picker Let me know if you need any more help. I used cloudinary with this package.

_onPhotoPress = async (pic, uploaded) => {
    const image = await ImagePicker.openPicker({
      width: 300,
      height: 300,
      cropping: true,
      mediaType: 'photo'
    })

    await this.setState({
      [uploaded]: true,
      [pic]:
        Platform.OS === 'ios'
          ? image.sourceURL
          : image.path,
      loading: true
    })

    const data = new FormData()
    data.append('upload_preset', 'uru0tlag')
    data.append('file', {
      uri: image.path,
      type: 'image/jpeg',
      name: 'whatEver'
    })
    const upload = await fetch(
      `https://api.cloudinary.com/v1_1/xxx/image/xxx`,
      {
        method: 'post',
        body: data
      }
    )
    const uploadData = JSON.parse(upload._bodyText)
    if (pic === 'nid') {
      await this.setState({
        nidCopy: uploadData.secure_url,
        loading: false
      })
    } else {
      this.state.pics.push(uploadData.secure_url)
      await this.setState({
        loading: false
      })
    }
    console.log(this.state.pics)
  }
oferRounds commented 6 years ago

@kaiyes – sorry for my delay! That’s awesome, I was manage to succeed thanks to you! Thank you!

kaiyes commented 6 years ago

@oferRounds awesome man. So did you use this package or the other one I mentioned ? I guess both works. I just couldn't get it working. I still need to upload documents ( pdf files ) to cloudinary.

May be share the working code so me and others can benefit ? Thanks

oferRounds commented 6 years ago

@kaiyes I used your code basically to upload the image to Cloudinary. I do use react-native-image-crop-picker, but it’s for a different task; i.e., it has a different purpose compared to this library