I'm doing my first web app using nodeJS with expressJS, I'm trying to upload an image to my folder "uploads", and it's work, with multer, it's uploaded, but it isn't an image it's look like 3c1dgn4vcs3c33vd, I've seek on a lot of forums but I didn't find an answer for helping me, I don't know how can I display this image on my views ?_? You can check on my github (https://github.com/sovada/Harmony_Dev) the file who work with upload file is that: controller/adminController.js:81
app.post("/hd-admin/blog/added", multer({dest: "./assets/uploads"}).single("img"), function (req, res) {
var titleEN = req.body.titleEN,
titleFR = req.body.titleFR,
titleES = req.body.titleES,
contentEN = req.body.contentEN,
contentFR = req.body.contentFR,
contentES = req.body.contentES,
img = "img/" + req.file.originalname,
date = moment().format("DD/MM/YYYY"),
author = "Harmony_dev",
category = req.body.category,
url = req.body.URL;
var add = new blog ({
titleEN : titleEN,
titleFR : titleFR,
titleES : titleES,
contentEN : contentEN,
contentFR : contentFR,
contentES : contentES,
img : img,
date : date,
author : author,
category : category
}).save(function (err, data) {
!err ? res.redirect("/hd-admin/blog") : console.log("err");
});
});
And the view with the form : views/admin/blog/add.ejs:61.
<form method="post" action="/hd-admin/blog/added" class="form-to-add-post" enctype="multipart/form-data">
<input type="text" name="titleEN" placeholder="title english"/>
<input type="text" name="titleFR" placeholder="title french"/>
<input type="text" name="titleES" placeholder="title spanish"/>
<textarea name="contentEN">Content english</textarea>
<textarea name="contentFR">Content french</textarea>
<textarea name="contentES">Content spanish</textarea>
<input type="file" name="img"/>
<input type="text" name="category" placeholder="category"/>
<input type="text" name="URL" placeholder="url"/>
<input type="submit" />
</form>
And the view who display the images :
<article class="post">
<img src="/<%= data.img %>" alt="<%= data.title %>" title="<%= data.title %>"/>
<% if (lang === "en") { %>
<h1><%= data.titleEN %></h1>
<p><%= data.contentEN %></p>
<% } %>
<% if (lang === "fr") { %>
<h1><%= data.titleFR %></h1>
<p><%= data.contentFR %></p>
<% } %>
<% if (lang === "es") { %>
<h1><%= data.titleES %></h1>
<p><%= data.contentES %></p>
<% } %>
<div class="link">
<span><i class="pe-7s-user"></i> <%= data.author %></span>
<span><i class="pe-7s-date"></i> <%= data.date %></span>
<span><i class="pe-7s-folder"></i> <%= data.category %></span>
</div>
</article>
Thank's you, really.