This issue only occurs on Android devices after updating React Native from v0.63.4 to v0.65.1. For some strange reason, the first attempt at uploading a image file will immediately fail with the error TypeError: Network Request Failed.
Sometimes this does not occur at all on the first try. But on the second or third try it will succeed. Does anyone know why does this happen or how I can investigate this further?
Below is the code for handling file uploads.
const handleUpload = async (file) => {
const form = new FormData()
form.append('file', {
uri: file.uri, type: file.type, name: file.name
})
const token = await getItem(storageKey.token)
let req_headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
Authorization: `Bearer ${token}`,
};
fetch(`${API_URL}/upload`, {
method: 'POST',
body: form,
headers: req_headers
})
.then((response) => response.json())
.then((response) => {
console.log('response', response);
})
.catch((error) => {
console.log('error', error);
});
};