Using express-fileupload I have a JSON object of a file which I store in my database.
For example:
{
name: 'bear.jpg',
data: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff fe 00 3b 43 52 45 41 54 4f 52 3a 20 67 64 2d 6a 70 65 67 20 76 31 2e 30 20 28 75 73 69 ... 15948 more
bytes>,
size: 15998,
encoding: '7bit',
tempFilePath: '',
truncated: false,
mimetype: 'image/jpeg',
md5: '7505ae720e82ac3b807b3e39483bebab',
mv: [Function: mv]
}
I am currently using EJS.
How can I display this file in html?
I hope for something like:
<html>
<body>
<img src="<%= the-file %>" width="200" height="200">
</body>
</html>
This is not a duplicate of Convert buffer data to an image as it enquires to techniques for generic files and tags (another example could be a .glb
file with a <model-viewer>
tag), an image is only used as an example.