so this is my problem : my code just returning error 422 when send data from real devices, but doing good on emulator here is my form data code :
const data = new FormData();
data.append('approval_store_code', this.state.selectedApotik.store_code);
data.append('delivery_method_id', 1);
data.append('recipe_document_images[]', {
name: 'recipePhotos1',
type: 'image/jpeg',
uri:
Platform.OS === 'android'
? this.state.imageResep[0].uri
: this.state.imageResep[0].uri.replace('file://', ''),
});
and this is the code when i send to server
this.setState({spinner: true});
const response = await REQ.createRecipe(this.state.accessToken, data);
console.log(response);
if (response.status == 200) {
console.log(response);
this.setState({spinner: false});
this.props.navigation.navigate('SuccessFormPharmacy');
} else {
alert('error');
this.setState({spinner: false});
}
} catch (error) {
this.setState({spinner: false});
console.log('error send data : ', error);
alert('error send Data!');
return null;
}
the axios code :
return axios({
method: 'POST',
url: `${API.BASE_URL}/v1/pharmacy/order`,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${accessToken}`,
},
body: formData,
});
the weird thing is, i have try using fetch instead of axios, didn't work for real device, but doing good on emulator i have try save the image first to devices, it saved but didn't success sent to server
on real device returning Error 422