The file is not saved on the server. The path property returns undefined.
const uploadProfile = (req, res) => {
const form = formidable.IncomingForm();
form.uploadDir = `./images`;
form.keepExtensions = true;
form.parse(req, (err, fields, files) => {
if (err) {
return res.json("Formidable cannot parse the form");
}
console.log(files.image.path);
res.json(files.image.path);
});
};
const uploadProfile = (req, res) => {
const options = {
uploadDir: `./images`,
keepExtensions: true,
};
const form = new formidable.IncomingForm(options);
form.parse(req, (err, fields, files) => {
if (err) {
return res.json("Formidable cannot parse the form");
}
const {filepath, originalFilename, newFilename, size , mimetype} = files.image
//'image' is the fileName... files.fileName
console.log(newFilename, "...");
res.json(newFilename);
});
};
Read about migration from V1 to V2 or V3