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

124
Views
axios successful request but data is undefined

I'm uploading multiple files separately using axios.

This is the request(all the following code is inside an async function):

const proms = files.map(file => {
  let formData = new FormData();
  formData.append("file", file);
  return axios.post(`/upload/${userId}`, formData)
});

proms will be an array of promises so I proceed to Promise.all it:

const res = await Promise.all(proms)

If I do console.log(res) it shows a successfull response from server as you can see here:

Array(3) [ {…}, {…}, {…} ]​
  0: Object { data: {…}, status: 200, statusText: "OK", … }​​
    config: Object { timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", … }​​
    data: Object { fieldname: "file", originalname: "612_photo.jpg", encoding: "7bit", … }​​​
    destination: ********************​​****
    encoding: "7bit"​​​
    fieldname: "file"​​​
    filename: "/1648309550808-586868206.jpeg"​​​
    mimetype: "image/jpeg"​​​
    originalname: "612_photo.jpg"​​​
    path: ********************​​****
    size: 43267​​​
    <prototype>: Object { … }​​
    headers: Object { "content-length": "395", "content-type": "application/json; charset=utf-8" }​​
    request: XMLHttpRequest { readyState: 4, timeout: 0, withCredentials: false, … }​​
    status: 200​​
    statusText: "OK"​​
    <prototype>: Object { … }​
  1: Object { data: {…}, status: 200, statusText: "OK", … }​
  2: Object { data: {…}, status: 200, statusText: "OK", … }​
  length: 3​
  <prototype>: Array []

But then when I do console.log(res.data) it is undefined. What is happening here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

your response(res) is An array so you cant access res.data ,try :

res.forEach(item=>{console.log(item.data)})
about 4 years ago · Juan Pablo Isaza 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!