Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 30010

react native upload image to api got network error

$
0
0

hello i am trying to upload image to api using form-data but i am getting Network error

why i am getting this error i try to put image type manually but still not working from post man it work without any problem

 async ImageFormData() {    const {photo} = this.state;    console.log(photo);    const formData = new FormData();    formData.append('file', {      uri: photo.uri,      type: 'image/jpeg',      name: photo.name,    });    setTimeout(() => {      this.setState({isLoading: true}, () => {        this.uploadImage(formData);      });    }, 100);  }  async uploadImage(formData) {    console.log(formData);    const {cid, email, phone, name} = this.state;    console.log(cid, email, phone, name);    fetch('api,      {        method: 'POST',        headers: {'Content-Type': 'multipart/form-data',        },        body: formData,      },    )      .then((response) => response.json())      .then((responseJson) => {        console.log(responseJson);        this.info();      })      .catch((error) => {        console.log(error);      });  }}

TypeError: Network request failed at EventTarget.xhr.onerror (C:\feras\worker\node_modules\whatwg-fetch\dist\fetch.umd.js:473) at EventTarget.dispatchEvent (C:\feras\worker\node_modules\event-target-shim\dist\event-target-shim.js:818) at EventTarget.setReadyState (C:\feras\worker\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:575) at EventTarget.__didCompleteResponse (C:\feras\worker\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:389) at C:\feras\worker\node_modules\react-native\Libraries\Network\XMLHttpRequest.js:502 at RCTDeviceEventEmitter.emit (C:\feras\worker\node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189) at MessageQueue.__callFunction (C:\feras\worker\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425) at C:\feras\worker\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112 at MessageQueue.__guard (C:\feras\worker\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373) at MessageQueue.callFunctionReturnFlushedQueue (C:\feras\worker\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111)


Viewing all articles
Browse latest Browse all 30010

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>