Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
Sending a csv from front-end to backend using axios

I am trying to send a csv file from my front end in reactjs to my back end in nodejs using axios. This csv file is selected via a browse UI button and stored in state using react. After searching online this is my code for the HTTPS request:

let formmData = new FormData();
formData.append('file', this.state.selectedFile);
           
const {data : QueryResult} = await axios({
    method: 'post',
    url: "https://localhost:...",
    formData,
});

Note: this.state.selectedFile contains an object which when logged on console is:

File {name: "MyFile.csv", lastModified: 1614958303483, …}

I also would like to say that this endpoint works fine when using Postman as seen below:

enter image description here

After printing the request in my back-end in the case this request from my frontend I see:

body: {}

I don't understand what I am doing wrong and this passes nothing to my back-end.

I also saw that this was an open issue with axios on GitHub in the past.

Can this be achieved now with axios or should i use another module? Any ideas?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to do:

await axios({
  method: 'post',
  url: "https://localhost:...",
  data: formData
});

because when you write just "formData", it becomes : { formData: formData } as per (new ES2015 object shorthand property name).

You can also use:

await axios.post('your_url', formData) 
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!