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 object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer 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, and can be used in any context that a Blob can. In particular, FileReader, URL.createObjectURL(), createImageBitmap(), and XMLHttpRequest.send() accept both Blobs and Files.

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


Returns a newly constructed File.


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

File implements Blob, so it also has the following properties available to it:

File.size Read only
Returns the size of the file in bytes.
File.type Read only
Returns the MIME type of the file.


The File interface doesn't define any methods, but inherits methods from the Blob interface:

Blob.slice([start[, end[, contentType]]])
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

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support13 Yes


3 — 71

File() constructor13 No7 No11.510.1
lastModified13 Yes151016 No
lastModifiedDate131215 — 611016 No
name13123.61016 Yes
type13 Yes3.61016 Yes
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes


4 — 71

11.16 Yes
File() constructor Yes Yes Yes7 No6 Yes
lastModified Yes Yes Yes No No No Yes
lastModifiedDate Yes Yes Yes No No No Yes
name Yes Yes Yes No No No Yes
type Yes Yes Yes No No No Yes

1. Non-standard implementation.


Implementation notes

  • In Gecko, you can use this API from within chrome code. See Using the DOM File API in chrome code for details. To use it from chrome code, JSM, and Bootstrap scope, you have to import it using Cu.importGlobalProperties(['File']);
  • Starting from Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), privileged code (such as extensions) can pass an nsIFile object to the DOM File constructor to specify the file to reference.
  • Starting from Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5), you can use new File to create File objects from XPCOM component code instead of having to instantiate the nsIDOMFile object directly. The constructor takes, in contrast to Blob, as second argument the filename. The filename can be any String.
    new File(
      Array parts,
      String filename, 
      BlobPropertyBag properties
  • The following non-standard properties and methods were removed in Gecko 7 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4): File.fileName, File.fileSize, File.getAsBinary(), File.getAsDataURL(), File.getAsText(string encoding) (bug 661876). Standard properties, Blob.size, and methods on FileReader should be used instead.

See also