Nework failed issue during post method

This issue has been tracked since 2022-09-22.

Description

here i'm trying to upload data with image from android app to code igniter server but its shows an error every time

Version

0.66.0

Output of npx react-native info

System:
OS: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
CPU: (4) x64 Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz
Memory: 2.13 GB / 7.66 GB
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 12.22.9 - /usr/bin/node
Yarn: Not Found
npm: 8.5.1 - /usr/bin/npm
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java: 11.0.16 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.66.0 => 0.66.0
npmGlobalPackages:
react-native: Not Found

Steps to reproduce

const formData = new FormData();

formData.append('u_id', u_id);
// formData.append('image', {
//   uri: get_data.Step_1_data[0].image.uri,
//   type: get_data.Step_1_data[0].image.type,
//   name: get_data.Step_1_data[0].image.fileName,
// });
formData.append('cat_id', get_data.Step_1_data[0].category.value);
formData.append('title', get_data.Step_1_data[0].category.value);
formData.append('discription', get_data.Step_1_data[0].description);
formData.append('publish_date', get_data.Step_1_data[0].publish_Date);
formData.append('expairy_date', get_data.Step_1_data[0].expire_date);
formData.append(
  'department_id',
  get_data_2.Step_2_data[0].Departement_id.value,
);
formData.append('cource_id', get_data_2.Step_2_data[0].Course_id.value);
formData.append('delivery_type', 1);
console.log(formData);
await fetch(BaseUrl + 'st_create_notice', {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'content-type': 'multipart/form-data',
  },
  body: formData,
})
  .then(Response => Response.json())
  .then(async data => {
    if (data.error_code == 200) {
      // return JSON.stringify(data);
    } else {
      console.log('abc');
      console.log(data);
    }
  });

whats wrong here i also try to send without image

Snack, code example, screenshot, or link to a repository

Screenshot from 2022-09-22 19-28-11

pablolucas890 wrote this answer on 2022-09-22

Can u try with axios?

Recentrly i hava same problem with the natural node fetch so, before a litle bit work, i'm use the axios post and the code working

rahulnainwal107 wrote this answer on 2022-09-27

There is issue with fetch in react-native. You can check this issue #28551.

Akintunji wrote this answer on 2022-10-01

Please I'm having the same issue too
"Unhandled promise rejection:TypeError: Network request failed". Please any solution to this

Akintunji wrote this answer on 2022-10-01
More Details About Repo
Owner Name facebook
Repo Name react-native
Full Name facebook/react-native
Language JavaScript
Created Date 2015-01-09
Updated Date 2022-10-03
Star Count 105144
Watcher Count 3666
Fork Count 22469
Issue Count 2232

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date