Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to send formdata and image file in react native expo?

Hi Everyone I want to send Formdata which includes some strings and an image file using react native expo to node server and mongo db can someone explain how can I do this using react native expo I have tried several methods but I am not successful however I am able to send data using backend but I don’t know how to send using React native expo?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

one of the libraries you can use to send data from react native is Axios
you can install it via :

npm i axios

and here is how you can send data with that :

You can post axios data by using FormData() like:

var bodyFormData = new FormData();

And then add the fields to the form you want to send in case you can use append:

bodyFormData.append('userName', 'Fred');

If you are uploading images, you may want to use .append

bodyFormData.append('image', imageFile); 

And then you can use axios post method (You can amend it accordingly)

axios({
  method: "post",
  url: "myurl",
  data: bodyFormData,
  headers: { "Content-Type": "multipart/form-data" },
})
  .then(function (response) {
    //handle success
    console.log(response);
  })
  .catch(function (response) {
    //handle error
    console.log(response);
  });

related documents you may be interested in:
https://axios-http.com/docs/api_intro

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading