Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

282
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!