I am designing a CRUD with images, using Mongodb with Nodejs and for the PUG views, but I have a problem when displaying the images; using the browser element inspector, it just tells me that could not load the image , I'm thinking that the problem is in the show file of the views, when doing the concatenation of variables, to tell the browser in which folder the image is. This would be my code from the show.pug file
extends ../../layout.pug
block contenido
div(class="img-container")
h1 #{imagen.title}
img(src="public/imagenes/+{imagen._id}+.+{imagen.extension}" alt= imagen._id)
if(typeof imagen.creator != "undefined")
p Por #{imagen.creator.email}
And this would be the POST function code to save the images
.post (function (req, res) { console.log (req.files.archivo)
var extension = req.files.archivo.name.split(".").pop();
var data = {
title: req.body.title,
creator: res.locals.user._id,
extension: extension
}
var imagen = new Imagen(data);
imagen.save(function(err){
if(!err){
var url = "public/imagenes/"+imagen._id+"."+extension
fs.copy(req.files.archivo.path, "public/imagenes/"+imagen._id+"."+extension)
console.log(url)
res.redirect("/app/imagenes/"+imagen._id)
}
else{
res.render(err)
}
})
})
The images are not being saved as such in the database, but they are stored in a static folder called public / images using fs.copy, and they are called from there to the view Please help me :( I am thinking that the error is in the show.pug, that is, the syntax to concatenate the variable with the image id plus the variable with the extension of the image