Using HTML5 and the File API
The images sources will be a URL representing the Blob object
<img src="blob:null/026cceb9-edr4-4281-babb-b56cbf759a3d">
const EL_browse = document.getElementById('browse');_x000D_
const EL_preview = document.getElementById('preview');_x000D_
_x000D_
const readImage = file => {_x000D_
if ( !(/^image\/(png|jpe?g|gif)$/).test(file.type) )_x000D_
return EL_preview.insertAdjacentHTML('beforeend', `Unsupported format ${file.type}: ${file.name}<br>`);_x000D_
_x000D_
const img = new Image();_x000D_
img.addEventListener('load', () => {_x000D_
EL_preview.appendChild(img);_x000D_
EL_preview.insertAdjacentHTML('beforeend', `<div>${file.name} ${img.width}×${img.height} ${file.type} ${Math.round(file.size/1024)}KB<div>`);_x000D_
window.URL.revokeObjectURL(img.src); // Free some memory_x000D_
});_x000D_
img.src = window.URL.createObjectURL(file);_x000D_
}_x000D_
_x000D_
EL_browse.addEventListener('change', ev => {_x000D_
EL_preview.innerHTML = ''; // Remove old images and data_x000D_
const files = ev.target.files;_x000D_
if (!files || !files[0]) return alert('File upload not supported');_x000D_
[...files].forEach( readImage );_x000D_
});
_x000D_
#preview img { max-height: 100px; }
_x000D_
<input id="browse" type="file" multiple>_x000D_
<div id="preview"></div>
_x000D_
In case you need images sources as long Base64 encoded data strings
<img src="data:image/png;base64,iVBORw0KGg... ...lF/++TkSuQmCC=">
const EL_browse = document.getElementById('browse');_x000D_
const EL_preview = document.getElementById('preview');_x000D_
_x000D_
const readImage = file => {_x000D_
if ( !(/^image\/(png|jpe?g|gif)$/).test(file.type) )_x000D_
return EL_preview.insertAdjacentHTML('beforeend', `<div>Unsupported format ${file.type}: ${file.name}</div>`);_x000D_
_x000D_
const reader = new FileReader();_x000D_
reader.addEventListener('load', () => {_x000D_
const img = new Image();_x000D_
img.addEventListener('load', () => {_x000D_
EL_preview.appendChild(img);_x000D_
EL_preview.insertAdjacentHTML('beforeend', `<div>${file.name} ${img.width}×${img.height} ${file.type} ${Math.round(file.size/1024)}KB</div>`);_x000D_
});_x000D_
img.src = reader.result;_x000D_
});_x000D_
reader.readAsDataURL(file); _x000D_
};_x000D_
_x000D_
EL_browse.addEventListener('change', ev => {_x000D_
EL_preview.innerHTML = ''; // Clear Preview_x000D_
const files = ev.target.files;_x000D_
if (!files || !files[0]) return alert('File upload not supported');_x000D_
[...files].forEach( readImage );_x000D_
});
_x000D_
#preview img { max-height: 100px; }
_x000D_
<input id="browse" type="file" multiple>_x000D_
<div id="preview"></div>_x000D_
_x000D_