Ошибка при передаче данных на сервер
Ошибка: PayloadTooLargeError: request entity too large
Отправляю текст и фото на сервер. html выглядит так:
form.wrapper__block-form.wrapper__block-form-add-post(action="/profile/post/" + user._id method="POST")
label.form__label(for="post-message")
h3.form__label-title Сообщение
textarea.form__input(placeholder="Написать сообщение" id="post-message" name="text" required)
.form__block.form__block--bd
.form__block
label.form__label(for="img-file-post")
input.form__file(type="file" id="img-file-post" multiple name="imgFile")
img.form__picture(src="/picture.svg", alt="Изображение")
p.form__desc Вы можете выбрать одно или несколько изображений (png, svg, jpg)
.form__block
ul.form__images-post
input.form__submit(style="margin: 0 auto;" type="submit" value="Добавить")
client:
function submitForm(e) {
e.preventDefault();
const res = {
id: window.location.pathname.replace(/\/profile\//, ''),
images: images_of_post
};
fetch(`http://localhost:3000/profile/post/${res.id}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(res)
});
}
В images_of_post содержатся объекты с url фото (с помощью new FileReader) и его именем
server:
router.post('/post/:id', async (req, res) => {
try {
const { text, images } = req.body;
const findUser = await User.findById(req.params.id);
const newPost = new Post({
userId: findUser._id,
user: findUser,
images: images ?? [],
text,
date: new Date(),
comments: []
})
await newPost.save();
res.redirect('/');
} catch (e) {
res.status(404).json({ message: e.message });
}
})