Get the properties of the file
suggest changeIf you want the name or the size, read them from the File before starting a FileReader. Given this HTML:
<input type="file" id="newFile">
You can access the properties directly like this:
document.getElementById('newFile').addEventListener('change', getFile);
function getFile(event) {
const files = event.target.files
, file = files[0];
console.log('Name of the file', file.name);
console.log('Size of the file', file.size);
}
You can also read lastModified (milliseconds since the epoch), type (the MIME type), and the deprecated lastModifiedDate (a Date). Prefer lastModified.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents