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

284
Vistas
postMessage validation failed error occurring during image upload using react-base64

I am uploading an image and saving it to mongodb but it is showing following error:

message: "postMessage validation failed: selectedFile: Cast

name: "ValidationError"

_message: "postMessage validation failed"

I am using react-base64 on the front end side to upload the image.

<FileBase type="file" multiple={false} onDone={(base64) => setPostData({ ...postData, selectedFile: base64})} />

And i am adding it to DB via fetch :

let handleSubmit = (event) => {
        event.preventDefault();
        console.log(postData);
        fetch(`http://localhost:5000/posts/create`, {
            method: 'POST',
            mode: 'cors',
            headers: {
                'Content-Type': 'application/json',
                // 'Accept': 'application/json'
            },
            body: JSON.stringify(postData),
        })
        .then(response => response.json())
        .then((dataFromServer) => {
            console.info(dataFromServer);
        })
        .catch(error => console.error(error));

    }

Can anyone tell me what I am doing wrong and how can i fix this issue

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

0

In the FileBase component, you need to do in this way.

You need to destructure the parameter on onDone. In this way onDone={({base64}) => yourFunction()}

You can use this one.

<FileBase type="file" multiple={false} onDone={({base64}) => setPostData({ ...postData, selectedFile: base64})} />
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