使用React-Base64在图像上传过程中发生后验证失败的错误失败
我正在上传图像并将其保存到mongodb,但它显示以下错误:
消息:“后验证验证失败:selectedfile:cast
名称:“验证”
_message:“邮政验证失败”
我正在前端使用React-Base64来上传图像。
<FileBase type="file" multiple={false} onDone={(base64) => setPostData({ ...postData, selectedFile: base64})} />
我通过获取将其添加到DB:
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));
}
谁能告诉我我在做什么错,我该如何解决这个问题
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在文件库组件中,您需要以这种方式进行。
您需要在
ondone
上破坏参数。这样,ondone = {({base64})=&gt; yourFunction()}
You can use this one.
In the FileBase component, you need to do in this way.
You need to destructure the parameter on
onDone
. In this wayonDone={({base64}) => yourFunction()}
You can use this one.