The File interface provides information about files and allows JavaScript in a web page to access their content.

File objects are generally retrieved from a FileList (en-US) object returned as a result of a user selecting files using the <input> (en-US) element, from a drag and drop operation's DataTransfer (en-US) object, or from the mozGetAsFile() API on an HTMLCanvasElement. In Gecko, privileged code can create File objects representing any local file without user interaction (see Implementation notes for more information.)

A File object is a specific kind of a Blob (en-US), and can be used in any context that a Blob can. In particular, FileReader (en-US), URL.createObjectURL() (en-US), createImageBitmap() (en-US), and XMLHttpRequest.send() accept both Blobs and Files.

See Using files from web applications for more information and examples.

Blob (en-US) File


Returns a newly constructed File.


File.lastModified (en-US) Read only
Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).
File.lastModifiedDate (en-US) Read only Deprecated
Returns the last modified Date of the file referenced by the File object. (en-US) Read only
Returns the name of the file referenced by the File object.
File.webkitRelativePath (en-US) Read only Non-Standard
Returns the path the URL of the File is relative to.

File implements Blob (en-US), so it also has the following properties available to it:

File.size (en-US) Read only
Returns the size of the file in bytes.
File.type (en-US) Read only
Returns the MIME type of the file.


The File interface doesn't define any methods, but inherits methods from the Blob (en-US) interface:

Blob.slice([start[, end[, contentType]]]) (en-US)
Returns a new Blob object containing the data in the specified range of bytes of the source Blob.


Specification Status Comment
File API Working Draft Initial definition

Browser compatibility

BCD tables only load in the browser


Implementation notes

See also