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

422
Vistas
Can't upload images to strapi via next.js api route

I have a complex form with a few file uploads, and I made it using react-hook-form with react-dropzone for file upload, data from the form is stored in react context.

Now at the last step of the form, I load data from react-context and I'm sending it to Strapi CMS via next.js API routes, and everything except file upload works fine. I always get error 500, but from the Altair client, I can upload it normally.

files data than I'm sending looks (logo in the code bellow):

enter image description here

upload files next.js api route:

const fRes = await api.upload('api/upload-files', data.logo)

api.upload:

async upload(endpoint: string, body) {
    const response = await fetch(endpoint, {
        method: 'POST',
        headers: {
            'Content-Type': 'multipart/form-data',
        },
        body: JSON.stringify(body),
    })
    if (!response.ok) {
        throw new Error(`Error: ${response.status}`)
    }

    const res = await response.json()
    return res
}

pages/api/upload-files:

import { NextApiRequest, NextApiResponse } from 'next'

import { apolloClient } from 'lib/apolloClient'
import { UPLOAD_FILES_MUTATION } from 'lib/models/Registration'

export default async (req: NextApiRequest, res: NextApiResponse) => {
console.log(req.body)
const { errors, data } = await apolloClient.mutate({
    mutation: UPLOAD_FILES_MUTATION,
    variables: { files: req.body },
})

if (errors) {
    return res.status(400).json(errors)
}

return res.status(200).json(data)
}

graphql mutation:

mutation ($files: [Upload]!) {
        multipleUpload(files: $files) {
            data {
                id
                attributes {
                    name
                }
            }
        }
    }
about 4 years ago · Juan Pablo Isaza
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