Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

148
Vistas
Append FormData to axios data

So I want to append formData multiple files to axios post. What I have:

const formData = new FormData();
  for (const i of Object.keys(item_images)) {
       formData.append('item_images[]', item_images[i]);
  }

http({
     method: el.method,
     url: el.action,
     data: {
             name: name,
             files: formData
           }
    })

But this doesn't work and it returns me empty request of files:

  'files' => 
  array (
  ),

But when I change axios to this it works and returns files:

http({
     method: el.method,
     url: el.action,
     data: formData
    })

But I need to make first one to work. What could be wrong?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Form Data objects do not support serialization to JSON.

You need to pick multipart or JSON as you data format and stick with it.

If you go with JSON then you'll need to convert your files to a data format you can encode in JSON (e.g. Base 64 strings) and then convert them back on the server.

If you go with multipart, then you'll need to append all your data, not just the files, to the formData object.

formData.append('name', name);
about 4 years ago · Juan Pablo Isaza Denunciar

0

You probably need to append all the data in your method one by one. And then in the axios call, you have to specify a content-type header like this:

axios.post('call/some/api', data, {
  headers: {
    'Content-Type': 'multipart/form-data',
  },
});

Hope it works!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda