Get the properties of the file

suggest change

If 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents