title: How to read csv file and upload in react js post method?
body: <p>I am new to react js and I am trying to read a csv file and upload all content to backend api.</p>
  
  <p>I am able to read the csv file and I can also print its content in console.log but when I try to post the same content it is not loading.</p>
  
  <p>I don't know where the error is. Here is my code:</p>
  
  <p>-using this funtion I can read the file and see all details in console, I need to put <code>csv</code> into <code>handlesubmit</code> function</p>
  
  <pre><code>read(e) {
      const reader = new FileReader();
      const csv1 = e.target.files[0];
      reader.readAsText(csv1);
      reader.onload = function(e) {
        var csv = e.target.result;
        // this.setState({
        //   csv
        // });
      };
    }
  </code></pre>
  
  <p>-this is handleSubmit function form where I have to upload file</p>
  
  <pre><code>handleSubmit(e) {
      e.preventDefault();
      let authToken = localStorage.getItem("Token");
  
      const reader = new FileReader();
      reader.onload = () =&gt; {
        csv.parse(reader.result, (err, data) =&gt; {
          var userList = [];
          const csv = data;
          const newUser = {
            csv: csv
          };
          userList.push(newUser);
        });
      };
      const data = {
        cost_type: this.state.cost_type,
        invoice_number: this.state.invoice_number,
        csv: this.state.csv, // this is name where i need to upload all csv file content 
        mapping: { ...this.state.mapping },
        start_row: this.state.start_row
      }
      axios({
        method: "post",
        url: `https://digitalfleet.eu/api/1/costs/upload/`,
        headers: {
          Accept: "application/json",
          "Content-Type": "application/json",
          Authorization: "Bearer " + JSON.parse(authToken)
        },
        data
      })
        .then(res =&gt; {
          this.setState({
            cost_type: null,
            invoice_number: "",
            csv: "",
            mapping: {
              date: "",
              car: "",
              car_vin: "",
              car_plate_number: "",
              car_mileage: "",
              value: "",
              invoice_number: "",
              cost_type: "",
              description: "",
              net_value: "",
              quantity: ""
            },
            start_row: null
          });
         console.log("success")
        })
        .catch(err =&gt; {
          console.log(err);
        });
      }
  </code></pre>
  
  <p>-this is the input field</p>
  
  <pre><code>&lt;div class="upload-btn-wrapper"&gt;
      &lt;button class="btn112" style={{ fontSize: "16px" }}&gt;
       selectfile
        &lt;/button&gt;
        &lt;input
          type="file"
          name="csv"
          onChange={this.read.bind(this)}
        /&gt;
    &lt;/div&gt;
  </code></pre>