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

588
Vistas
send file from nextjs API Routes

I use nextjs API Routes to connect to an external API

when I use a POST request to send a file, the file doesn't handled correctly in API Routes and I get 422 Unprocessable Entity Error

when I send only text it's OK, but when I add a file this error occur.

my request

const data = new FormData();
        data.append('first_name', firstName);
        data.append('last_name', lastName);
        data.append('phone_number', phoneNumber);
        image && data.append('avatar', image);

        axios.post(`${API_ROUTE}`, data, {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        })
        .then(res=>{
            alert(JSON.stringify(res.data, null, 2));
        })

my API Route

    const config = {
        headers: {
            'Content-Type': req.headers['content-type']
        }
    };

    axios.post(address, req.body, config)
    .then(r=>{
        res.statusCode = 200
        res.json( r.data )
    })
    .catch(err=>{
        res.json(err)
    })

in the request that API Route sending to the external API, there are some ? in the content of the file, but in the request that sending from browser to the API Route seems there are different characters

over 4 years ago · Santiago Trujillo
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