I'm getting this weird error whenever I try to post something on my site. It is a field where the user can enter text or enter a media file such as photo or video. But when I try to enter text this error is returned.So I just can't post anything text or image.
{statusCode: 400, error: "Bad Request", message: "celebrate request validation failed",…}
error: "Bad Request"
message: "celebrate request validation failed"
statusCode: 400
validation: {body: {source: "body", keys: ["file"], message: ""file" is not allowed"}}
body: {source: "body", keys: ["file"], message: ""file" is not allowed"}
keys: ["file"]
message: "\"file\" is not allowed"
source: "body"
My Front End is built with React.
const handleStoryCreate = useCallback(async () => {
try {
setLoading(true);
const data = {
text: inputValue,
};
const schema = Yup.object().shape({
text: Yup.string().required('Texto obrigatório'),
});
await schema.validate(data, { abortEarly: false });
const formData = new FormData();
formData.append('text', data.text);
formData.append('file', fileImage);
await api.post('stories', formData, {
headers: {
'content-type': 'multipart/form-data',
Authorization: `Bearer ${session.accessToken}`,
},
});
Here the route:
router.post(
'/',
ensureAuthorization('user'),
ensureFiles('file', false),
resize,
celebrate({
[Segments.BODY]: {
text: Joi.string().required(),
},
}),
storiesController.create,
);