React Native Android device throws error for Fetch while uploading a json file : TypeError: Network request failed2019 Community Moderator ElectionAndroid error: Failed to install *.apk on device *: timeoutReact Native android build failed. SDK location not foundReact Native Post Request via Fetch throws Network Request FailedReact Native fetch() Network Request Failedreact-native android Could not retrieve file for contentUri http://192.168.108.18:8180/app/upload/storag/app_head/201610131627080535.jpgRedirect url is not working in fetch APIReact Native fetch TypeError: Network request failedNetwork request failed React native fetch (Android)React native TypeError: Network request failed with fetch()React native fetch request failed

What does a stand alone "T" index value do?

Can't find the Shader/UVs tab

Make a transparent 448*448 image

What wound would be of little consequence to a biped but terrible for a quadruped?

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

Am I not good enough for you?

BitNot does not flip bits in the way I expected

Does splitting a potentially monolithic application into several smaller ones help prevent bugs?

Why is there a voltage between the mains ground and my radiator?

Is there an elementary proof that there are infinitely many primes that are *not* completely split in an abelian extension?

Built-In Shelves/Bookcases - IKEA vs Built

Algorithm to convert a fixed-length string to the smallest possible collision-free representation?

Reverse string, can I make it faster?

Unreachable code, but reachable with exception

The bar has been raised

Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?

Is it true that real estate prices mainly go up?

How do I locate a classical quotation?

Examples of a statistic that is not independent of sample's distribution?

How to create a hard link to an inode (ext4)?

Are babies of evil humanoid species inherently evil?

Aliens englobed the Solar System: will we notice?

What to do when during a meeting client people start to fight (even physically) with each others?



React Native Android device throws error for Fetch while uploading a json file : TypeError: Network request failed



2019 Community Moderator ElectionAndroid error: Failed to install *.apk on device *: timeoutReact Native android build failed. SDK location not foundReact Native Post Request via Fetch throws Network Request FailedReact Native fetch() Network Request Failedreact-native android Could not retrieve file for contentUri http://192.168.108.18:8180/app/upload/storag/app_head/201610131627080535.jpgRedirect url is not working in fetch APIReact Native fetch TypeError: Network request failedNetwork request failed React native fetch (Android)React native TypeError: Network request failed with fetch()React native fetch request failed










0















I have written code to call Fetch method to Post Json file to IPFS .
I am writing the JSON file locally which succeds , but later when i call the POST method using FORMDATA to write json file to IPFS it fails.
Same code works fine on iOS . Not sure what is the issue with Android.



Also tried using IP of the server , using xmlhttprequest , different options for setting cors/no-cors etc but still getting the same error .



I am using Android version 8.0, Reactnative version 0.57 and "react-native-fs": "^2.13.3".
Can somebody suggest an alternate way to make network calls.Cant use native code as this code is in JS library.Kindly provide your valuable feedback.
Below is the code snippet :



justcall(valueToWrite)
var path = RNFS.DocumentDirectoryPath + '/writeddo.json';
//var path = RNFS.LibraryDirectoryPath + '/writeddo.json';
console.log("path",path);
return new Promise((resolve, reject) =>
// write the file
RNFS.writeFile(path, valueToWrite,'utf8')
.then((success) =>
console.log('FILE WRITTEN!');
let formdata = new FormData();
formdata.append('file',
uri: path,
name: 'writeddo.json',
type: 'multipart/form-data'
);
console.log("formdata",formdata);
console.log("IPFSADD Url",IPFSADD);

fetch(IPFSADD,
method: 'POST',
headers:
// 'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
,
//mode: "no-cors", //, cors, *same-origin
body: formdata
)
// .then((serviceResponse) => return serviceResponse.json() )
.then((serviceResponse) =>
console.log("Justcall response", serviceResponse);
return this.deleteJsonFile(path).then(() =>
resolve(serviceResponse)
)
.catch((error) =>
console.error("Error while deleting the file error:", error)
reject(new Error(error))
)
)
.catch((error) =>
console.error("fetch error:", error)
reject(new Error(error))
)

) // Write File
.catch((err) =>
console.log("Error while writing file locally" +err.toString());
reject(new Error(err))
);
) //Promise




fetch error: TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (whatwg-fetch.js:504)
at XMLHttpRequest.dispatchEvent (event-target.js:172)
at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
at XMLHttpRequest.js:507
at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
at MessageQueue.__callFunction (MessageQueue.js:349)
at MessageQueue.js:106
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)









share|improve this question


























    0















    I have written code to call Fetch method to Post Json file to IPFS .
    I am writing the JSON file locally which succeds , but later when i call the POST method using FORMDATA to write json file to IPFS it fails.
    Same code works fine on iOS . Not sure what is the issue with Android.



    Also tried using IP of the server , using xmlhttprequest , different options for setting cors/no-cors etc but still getting the same error .



    I am using Android version 8.0, Reactnative version 0.57 and "react-native-fs": "^2.13.3".
    Can somebody suggest an alternate way to make network calls.Cant use native code as this code is in JS library.Kindly provide your valuable feedback.
    Below is the code snippet :



    justcall(valueToWrite)
    var path = RNFS.DocumentDirectoryPath + '/writeddo.json';
    //var path = RNFS.LibraryDirectoryPath + '/writeddo.json';
    console.log("path",path);
    return new Promise((resolve, reject) =>
    // write the file
    RNFS.writeFile(path, valueToWrite,'utf8')
    .then((success) =>
    console.log('FILE WRITTEN!');
    let formdata = new FormData();
    formdata.append('file',
    uri: path,
    name: 'writeddo.json',
    type: 'multipart/form-data'
    );
    console.log("formdata",formdata);
    console.log("IPFSADD Url",IPFSADD);

    fetch(IPFSADD,
    method: 'POST',
    headers:
    // 'Accept': 'application/json',
    'Content-Type': 'multipart/form-data',
    ,
    //mode: "no-cors", //, cors, *same-origin
    body: formdata
    )
    // .then((serviceResponse) => return serviceResponse.json() )
    .then((serviceResponse) =>
    console.log("Justcall response", serviceResponse);
    return this.deleteJsonFile(path).then(() =>
    resolve(serviceResponse)
    )
    .catch((error) =>
    console.error("Error while deleting the file error:", error)
    reject(new Error(error))
    )
    )
    .catch((error) =>
    console.error("fetch error:", error)
    reject(new Error(error))
    )

    ) // Write File
    .catch((err) =>
    console.log("Error while writing file locally" +err.toString());
    reject(new Error(err))
    );
    ) //Promise




    fetch error: TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (whatwg-fetch.js:504)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
    at XMLHttpRequest.js:507
    at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
    at MessageQueue.__callFunction (MessageQueue.js:349)
    at MessageQueue.js:106
    at MessageQueue.__guard (MessageQueue.js:297)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)









    share|improve this question
























      0












      0








      0








      I have written code to call Fetch method to Post Json file to IPFS .
      I am writing the JSON file locally which succeds , but later when i call the POST method using FORMDATA to write json file to IPFS it fails.
      Same code works fine on iOS . Not sure what is the issue with Android.



      Also tried using IP of the server , using xmlhttprequest , different options for setting cors/no-cors etc but still getting the same error .



      I am using Android version 8.0, Reactnative version 0.57 and "react-native-fs": "^2.13.3".
      Can somebody suggest an alternate way to make network calls.Cant use native code as this code is in JS library.Kindly provide your valuable feedback.
      Below is the code snippet :



      justcall(valueToWrite)
      var path = RNFS.DocumentDirectoryPath + '/writeddo.json';
      //var path = RNFS.LibraryDirectoryPath + '/writeddo.json';
      console.log("path",path);
      return new Promise((resolve, reject) =>
      // write the file
      RNFS.writeFile(path, valueToWrite,'utf8')
      .then((success) =>
      console.log('FILE WRITTEN!');
      let formdata = new FormData();
      formdata.append('file',
      uri: path,
      name: 'writeddo.json',
      type: 'multipart/form-data'
      );
      console.log("formdata",formdata);
      console.log("IPFSADD Url",IPFSADD);

      fetch(IPFSADD,
      method: 'POST',
      headers:
      // 'Accept': 'application/json',
      'Content-Type': 'multipart/form-data',
      ,
      //mode: "no-cors", //, cors, *same-origin
      body: formdata
      )
      // .then((serviceResponse) => return serviceResponse.json() )
      .then((serviceResponse) =>
      console.log("Justcall response", serviceResponse);
      return this.deleteJsonFile(path).then(() =>
      resolve(serviceResponse)
      )
      .catch((error) =>
      console.error("Error while deleting the file error:", error)
      reject(new Error(error))
      )
      )
      .catch((error) =>
      console.error("fetch error:", error)
      reject(new Error(error))
      )

      ) // Write File
      .catch((err) =>
      console.log("Error while writing file locally" +err.toString());
      reject(new Error(err))
      );
      ) //Promise




      fetch error: TypeError: Network request failed
      at XMLHttpRequest.xhr.onerror (whatwg-fetch.js:504)
      at XMLHttpRequest.dispatchEvent (event-target.js:172)
      at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
      at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
      at XMLHttpRequest.js:507
      at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
      at MessageQueue.__callFunction (MessageQueue.js:349)
      at MessageQueue.js:106
      at MessageQueue.__guard (MessageQueue.js:297)
      at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)









      share|improve this question














      I have written code to call Fetch method to Post Json file to IPFS .
      I am writing the JSON file locally which succeds , but later when i call the POST method using FORMDATA to write json file to IPFS it fails.
      Same code works fine on iOS . Not sure what is the issue with Android.



      Also tried using IP of the server , using xmlhttprequest , different options for setting cors/no-cors etc but still getting the same error .



      I am using Android version 8.0, Reactnative version 0.57 and "react-native-fs": "^2.13.3".
      Can somebody suggest an alternate way to make network calls.Cant use native code as this code is in JS library.Kindly provide your valuable feedback.
      Below is the code snippet :



      justcall(valueToWrite)
      var path = RNFS.DocumentDirectoryPath + '/writeddo.json';
      //var path = RNFS.LibraryDirectoryPath + '/writeddo.json';
      console.log("path",path);
      return new Promise((resolve, reject) =>
      // write the file
      RNFS.writeFile(path, valueToWrite,'utf8')
      .then((success) =>
      console.log('FILE WRITTEN!');
      let formdata = new FormData();
      formdata.append('file',
      uri: path,
      name: 'writeddo.json',
      type: 'multipart/form-data'
      );
      console.log("formdata",formdata);
      console.log("IPFSADD Url",IPFSADD);

      fetch(IPFSADD,
      method: 'POST',
      headers:
      // 'Accept': 'application/json',
      'Content-Type': 'multipart/form-data',
      ,
      //mode: "no-cors", //, cors, *same-origin
      body: formdata
      )
      // .then((serviceResponse) => return serviceResponse.json() )
      .then((serviceResponse) =>
      console.log("Justcall response", serviceResponse);
      return this.deleteJsonFile(path).then(() =>
      resolve(serviceResponse)
      )
      .catch((error) =>
      console.error("Error while deleting the file error:", error)
      reject(new Error(error))
      )
      )
      .catch((error) =>
      console.error("fetch error:", error)
      reject(new Error(error))
      )

      ) // Write File
      .catch((err) =>
      console.log("Error while writing file locally" +err.toString());
      reject(new Error(err))
      );
      ) //Promise




      fetch error: TypeError: Network request failed
      at XMLHttpRequest.xhr.onerror (whatwg-fetch.js:504)
      at XMLHttpRequest.dispatchEvent (event-target.js:172)
      at XMLHttpRequest.setReadyState (XMLHttpRequest.js:580)
      at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:394)
      at XMLHttpRequest.js:507
      at RCTDeviceEventEmitter.emit (EventEmitter.js:190)
      at MessageQueue.__callFunction (MessageQueue.js:349)
      at MessageQueue.js:106
      at MessageQueue.__guard (MessageQueue.js:297)
      at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:105)






      android react-native fetch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 7:36









      PawanPawan

      31




      31






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55038396%2freact-native-android-device-throws-error-for-fetch-while-uploading-a-json-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid …


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55038396%2freact-native-android-device-throws-error-for-fetch-while-uploading-a-json-file%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page