Closed kaiyes closed 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 ?
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)
})```
@kaiyes facing the same issue, did you find a solution?
@kaiyes what is data
? and what does the name
key refer to?
@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)
}
@kaiyes – sorry for my delay! That’s awesome, I was manage to succeed thanks to you! Thank you!
@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
@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