'Take a picture and after successfully receiving a response I we need to call the endpoint - REACT NATIVE
I have a screen where on click on image I need to open camera and take photo, I successfully open camera, take a picture but when I need to call the endpoints it show me error 415, unsupported media.
<TouchableOpacity style={{ alignSelf: 'center' }} onPress={() => onPressLaunchCamera(onSuccessPhotoUpload)}>
Here is my function
const onSuccessPhotoUpload = async (response: ImagePickerResponse): Promise<void> => {
let fileUri = '';
if (response?.assets) {
const formData = new FormData();
const requestBody = {
formFile: response.assets[0],
};
console.log(response);
fileUri = response?.assets[0].uri || '';
try {
Keyboard.dismiss();
if (challenge) {
formData.append('uploadPicture', {
uri: Platform.OS === 'android' ? fileUri : fileUri.replace('file://', ''),
type: 'multipart/form-data',
});
dispatch(uploadInvoice(challenge.id, requestBody));
}
} catch (error) {
Alert.alert('Something went wrong while getting your image from your photo library.');
}
}
Solution 1:[1]
415 Unsupported Media Type
Fixing a 415 error can be time-consuming for the client as it indicates the issue is in what the client is sending that the web server can't process. In other words, if you come across a 415 error, it means that you have to fix the error yourself.
Here are the three most common ways for fixing a 415 Unsupported Media Type:
Make sure that you are sending the right
Content-Type
header value.Confirm that the server can process the value defined in the
Content-Type
header.Check the Accept header to see what the server can process.
Source is Here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nooruddin Lakhani |