Buffer.from('your img buffer').toString('base64')
const decodeBase64Img = (base64String) => {
const matches = base64String.match(/^data:([A-Za-z-+/]+);base64,(.+)$/),
obj = {};
if (matches.length !== 3) {
return new Error('Invalid input string');
}
const [, extension, base64] = matches;
obj.type = extension;
obj.buffer = Buffer.from(base64, 'base64');
return obj;
// Based on: https://stackoverflow.com/Questions/20267939/Nodejs-Write-Base64-Image-File
};
await FileType.fromBuffer(decodeBase64Img('base64').buffer);
window.addEventListener("DOMContentLoaded",function(){
})
window.addEventListener('DOMContentLoaded',()=>{
});
<script src="" defer></script>
<html>
<head>
<title> Images view </title>
</head>
<body>
<script type="text/javascript">
var images = new Array();
var i = 0;
images[0] = './images/1.jpg';
images[1] = './images/2.jpg';
images[2] = './images/3.jpg';
function viewImages() {
document.getElementById("img_main").src = images[i];
i++;
if (i == images.length) {
i = 0;
}
setTimeout("viewImages()",5000);
}
</script>
<img src="" id="img_main">
<script> viewImages(); </script>
</body>
</html>