React : POST http://localhost:8081/upload 500 (Internal Server Error) and Request failed with status code 500
-
Client.js
const uploadUpload = async (e) => {
e.preventDefault();
const formdata = new FormData();
formdata.append("imageFile", image);
try {
console.log(image);await axios({
method: "POST",
url: "http://localhost:8081/upload",
headers: { "content-type": "multipart/form-data" },
data: formdata, // Try this line
});
} catch (err) {
console.log("ERROR", err);
}};
Server.jsconst storage =......
const upload = multer({
storage: storage,
}).single("imageFile");
app.post("/upload", upload, async (req, res) => {
const image = req.file.filename;
const sql = "INSERT INTO imageTable (imgeName) VALUES (?)";
db.query(sql, [image], (err, result) => {
if (err) return res.json({ Message: "ERROR INSIDE SERVER" });
return res.json(result);
});
console.log(imageFile.filename);
});The name of the image is saved in the database, the image has been uploaded to the 'public/image' folder, but it gives me the errors
POST http://localhost:8081/upload 500 (Internal Server Error) and Request failed with status code 500