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

140
Vistas
Not able to upload file using formik.from postman API is working

I have created below API. it is perfectly working from postman.

@Controller('certificates')
export class CertificatesController {
    constructor(private readonly certificatesService: CertificatesService) {}

    @Post('upload')
    @UseInterceptors(
        FileInterceptor('attachedFile', {
            storage: diskStorage({
                destination: './uploads',
                filename(_, file, callback) {
                    const randomName = Array(32)
                        .fill(null)
                        .map(() => Math.round(Math.random() * 16).toString(16))
                        .join('');
                    return callback(null, `${randomName}${extname(file.originalname)}`);
                },
            }),
        })
    )
    uploadFile(@UploadedFile() file) {
        console.log(file);
        return {
            url: `http://localhost:8000/api/uploads/${file.filename}`,
        };
    }
}

when I call it using postman enter image description here

but when I want to call the same using formik my API recive undefined in file.

 <input
          id="file"
          name="attachedFile"
          type="file"
          onChange={(event: any) => {
          setFieldValue(
         'file',
          event.currentTarget.files[0]
         );}}  />

const handleSubmit = async (values: any, httpClient: any, config: any) => {
    alert(values.attachedFile);  //it prints Object filelist
    const { data } = await axios.post(
        'http://localhost:3000/api/certificates/upload',
        values.attachedFile
    );

my API return below error and in UI I get 500.

enter image description here

why I am not able to send file along with post request? should I do something else? Other than file in another request I am able to send all the data. can you please help.

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