Skip to content

Instantly share code, notes, and snippets.

@JoeThunyathep
Created March 21, 2022 05:10
Show Gist options
  • Save JoeThunyathep/88fa0a19db745c7e04b98c878c99324d to your computer and use it in GitHub Desktop.
Save JoeThunyathep/88fa0a19db745c7e04b98c878c99324d to your computer and use it in GitHub Desktop.
<input type="file" id="fs" multiple>
const fileSelect = document.getElementById('fs');
fileSelect.addEventListener('change', (event) => {
const fileList = event.target.files;
for (const file of fileList) {
// Constructing Meta Data if support.
const name = file.name ? file.name : 'NOT SUPPORTED';
const type = file.type ? file.type : 'NOT SUPPORTED';
const size = file.size ? `${file.size/1000} KB` : 'NOT SUPPORTED';
// Log the filename/ type/ size in the browser console
console.log({file, name, type, size});
// Continue doing something with files...
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment