Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda