question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Axios don't send form data in react-native

See original GitHub issue

I’ve try to send a form data with axios but i can’t, in chrome dev tools no content appears in the request. Making a same request via postman the API response normally.

  (newData) => {
   const data = new FormData();
   data.append('name', 'raphael');
   data.append('file', {
       uri: newData.image.path,
       type: 'image/jpeg',
       name: 'teste'
   });
   return axios.post(`${constants.development.URL_API}/file`, data, 
       headers: {
           'Content-Type': 'multipart/form-data',
       },
   })`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:46 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
emilyemorehousecommented, Jul 4, 2018

Y’all, I appreciate the direction but “just test a file upload in React Native” isn’t that easy. I don’t often work in React Native and it would take a decent amount of time to spin up a project with file uploads to test with.

I do have a simple POST with form data that works in React Native:

    const formData = new FormData();
    formData.append("data", true);

    const config = {
      headers: {
        "Content-Type": "multipart/form-data; charset=utf-8;"
      }
    };

    axios.post(URL, formData, config).then(
      response => {
        console.log({ response });
      },
      error => {
        console.log({ error });
      }
    );

true gets stringified when sent to the server, which is interesting.

That said, if anyone can provide an example that I can easily spin up, I’m happy to look into it more.

14reactions
giladnocommented, Mar 9, 2018

This bug still happens with latest axios, why was this closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native post form data with object and file in it using axios
second problem is axios converts form data automatically to string, so you need to use transformRequest config on request to override it. import ......
Read more >
Steps to Send Form Data Using Axios Post Request in React
Here is the step-by-step guide to send form data using axios post request in React. Refer this article if you need this step-by-step...
Read more >
How to post form data with axios - LearnBestCoding
1. Install axios in your React project. If you haven't installed axios yet, you can run the below command to install axios. npm ......
Read more >
POST form data using Axios API in JavaScript (including a file)
Source code: https://openjavascript.info/2022/08/03/ post - form - data -using- axios /⚡ Looking for high-performance, affordable web hosting for ...
Read more >
How to post form-data with axios : r/reactnative - Reddit
I've been trying to post form-data but always get error. please help me solve it. here is Stackoverflow question in details.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found