Hakan Alp
Hakan Alp

Reputation: 121

React Native, getting network error while posting FormData with Axios

I am trying to send an audio/image by creating FormData.

My current versions are: "react-native": "0.59.10", "axios": "^0.19.2", "react": "16.8.3". And I am testing my app on my android device

and getting "network error" every single time while sending FormData.

here is my way of creating and sending post;

  let new_options = {
    headers: {
      'Content-Type': 'multipart/form-data',
      'Authorization': myAuthorization
    }
  };
  const content = new FormData();
  content.append('file', {
    uri: 'file://' + attachment.path,
    name: 'test',
    type:  attachment.type
  });
  content.append('ReportId', report_id);
  content.append('MimeType', attachment.type);
  
  try {
    let res = await axios.post(myUrl, content, new_options);
  }catch(err){
    console.warn(err);
  }

I already tried things like updating FLIPPER_VERSION or editing ReactNativeFlipper.java but none of this things exists in my project since I am using older version of react-native. I also tried to delete the debug folder.

Upvotes: 0

Views: 1213

Answers (1)

Hakan Alp
Hakan Alp

Reputation: 121

Figured it out, problem was caused by wrong MimeTypes.

Upvotes: 2

Related Questions