I am using express and multer to upload images. If I send the image to the intended folder but it does not save the path and it shows the error:
Cannot POST /api/imagen
const db = require("../models");
const multer = require("multer");
const path = require("path");
const Imagen = db.imagens;
let nameImage = "";
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, path.join(__dirname, "/uploads"));
},
filename: (req, file, cb) => {
const ext = file.originalname.split(".").pop();
nameImage = `${Date.now()}.${ext}`;
cb(null, nameImage);
},
});
const upload = multer({ storage });
(exports.create = upload.single("url")),
async (req, res) => {
try {
const data = await Imagen.create({
titulo: req.body.titulo,
url: nameImage,
});
res.send({
mesagge: "Imágen cargada!",
});
} catch (error) {
res.send(error);
}
};