I'm trying to display a BLOB
from from a mySQL
table as an image in an EJS
file but I cannot figure out how to do it. latestlistings[0].photo
is the image I need to display. This is how my EJS file looks like where I need to display the image
<div>
<%if (latestLocations[0]) {%>
<%=latestLocations[0].address%>,
<%=latestLocations[0].city%>,
<%=latestLocations[0].province_state%>,
<%=latestLocations[0].country%>
<%}%>
<%if (latestListings[0]) {%>
<%=latestListings[0].price%>
<img src="data:image/jpeg;base64,<%= latestListings[0].photo %>"/>
<%}%>
</div>
I'm not modifying the variable at all when I pass it into the EJS template. I'm pulling it straight from the database where it's stored as a LONGBLOB
. When I load the page, I just get an image icon which looks like this . When I print out the variable right before passing it into the EJS template, it looks like this
photo: <Buffer 49 4d 47 5f 32 34 35 35 2e 6a 70 67>
. I've been trying for ages trying to get this to work so any help is appreciated!