I am trying to upload an image but I am failed because I am new to React Native . Actually, I want to select a photo then upload it to my server , from app it not working . when I give it try from postman it working . In postman I select form-data
, In key I selected type as file
when I hit on submit then image is successfully uploaded but when I try it from app it not working . Could someone please help me how to achieve my goal.
code
_pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
quality: 1,
allowsMultipleSelection: true,
base64: true,
});
let pickerResult = await ImagePicker.launchImageLibraryAsync();
if (!result.cancelled) {
console.log('iff')
ext = result.uri.split('.').pop()
this.setState(prevState => ({
images: [...prevState.images, `data:image/${ext};base64,` + result.base64],
imageView: true
})
)
axios.post(`${apiUrl}/api/cloud/image`,{image:pickerResult})
.then(res=> {
console.log('@@@@@@ response',res.data)
})
.catch(error=> {
console.log('@@@@@@ error reponse',error.response.data)
})
// console.log('fffe', this.state.images)
// this.props.dispatch(uploadImage(this.state.images))
} else {
console.log('else')
}
};