I am trying to use it to send img
to multer
in node to upload the img
but always get me a null
I tryed to restart the whole project but nothing
here front part :
const addPostsHundler = (e) => {
e.preventDefault();
const form = new FormData().append("file", file);
console.log(data.user_id);
axios
.post("http://localhost:5000/Upload", {
form: form,
inputs: input,
userID: data.user_id,
})
.then((res) => {
console.log(res);
})
.catch((err) => console.log(err));
};
and back part :
const multer = require("multer");
let fileName;
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "../client/public/upload");
},
filename: function (req, file, cb) {
fileName = file.originalname;
cb(null, fileName);
},
});
app.post("/Upload", upload.single("file"), (req, res) => {
res.status(200).json({ message: "img stored", img: fileName });
});