Reputation: 9
//Frontend
const handlePost = async () => {
const formData = new FormData();
formData.append("userId", _id);
formData.append("description", post);
if (image) {
// console.log(image);
formData.append("picture", image);
formData.append("picturePath", image.name);
}
// console.log(formData);
const response = await fetch(`http://localhost:8080/posts`, {
method: "POST",
headers: { Authorization: `Bearer ${token}` },
body: formData,
});
const posts = await response.json();
dispatch(setPosts({ posts }));
setImage(null);
setPost("");
};
//Backend
const upload = multer({ storage });
app.post("/auth/register", upload.single("picture"), register);
app.post("/posts", upload.single("picture"), createPost);
i am trying to send image through react in frontend by appending in form but upload.single("picture") is not picking it up
Upvotes: 0
Views: 29