I wanted to get the image from MySQL using NodeJS, and EJS template. I think the problem is that I failed to transfer buff data into base64. I have tried many soluction out there but didn't work out. My currect code is ...
Index.ejs
<% for ( var i = newsData.length -1; i >= 0; i--){ %>
<img src="<%= newsData[i].image %>">
<h3><%= newsData[i].title %></h3> //Which is working
<p><%= newsData[i].content %></p> //Which is working
I have tried to use
<%- newsData[i].image %>
Which give me the result of ...
Website show data
routes.js
app.get('/news', isLoggedIn, function({user}, res, next) {
var newsData = '';
db.query('SELECT date,title,content,image FROM news', function(err, rows) {
if (err) {
console.log(err);
}
var newsData = rows;
// use index.ejs
res.render('../views/dashboard/html/table/news.ejs', { title: 'Account Information', newsData: newsData, user});
});
});
By the way, the image format that I stored in Mysql is "Blob". Thanks
kind regards.