For example, you could get the selected file size as the following
For the HTML bellow
In the example above, this.files exposes a FileList object, which is an array-like object of File objects.
As described by the File’s object HTML specification here are some other file properties you could retrieve.
name: Returns a string containing the file name (without the path information)
lastModifiedDate: Returns a Date object that represents the file last modified date
size: Returns an integer representing the file size in bytes
type: Returns a string with the file MIME type
This is a perfect solution for improving user experience while implementing file uploads and avoiding having to submit the file to have this kind of check only at the server side.
Other useful resources:
Originally posted by me at http://i.ndigo.com.br/2012/01/javascipt-checking-the-file-size