I have This code to uplad user table image Profile but when i upload image i get req File undefined
export const updateuser = async (id:number, image:any) => {
const formData = new FormData();
formData.append("image", {
uri: image,
name: "uploaded_image.jpg", // Customize the name
type: "image/jpeg", // Ensure it matches your image type
});
const response = await axios.put(`${API_URL}/image/${ id }`, { formData}, {
headers: {
"Content-Type": "multipart/form-data",
},
});
return response.data;
};
in backend
**********
const multer = require('multer')
const storage = multer.memoryStorage();
const upload = multer({ storage });
*******
router.put("/image/:id", upload.single("image"), async (req, res) => {
try {
const { id } = req.params; // Image ID to update
if (!req.file) {
return res.status(400).send("No file uploaded.");
}
await User.update({ image: req.file.buffer}, { where: { Id: id } });
res.sendStatus(200);
} catch (error) {
console.error(error);
res.sendStatus(500);
}
});
I have This code to uplad user table image Profile but when i upload image i get req File undefined
in backend