File objects are generally retrieved from a
FileList (en-US) object returned as a result of a user selecting files using the
<input> 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.)
File object is a specific kind of a
Blob (en-US), and can be used in any context that a Blob can. In particular,
createImageBitmap() (en-US), and
XMLHttpRequest.send() accept both
See Using files from web applications for more information and examples.
- Returns a newly constructed
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
- Returns the last modified
Dateof the file referenced by the
File.name(en-US) Read only
- Returns the name of the file referenced by the
File.webkitRelativePath(en-US) Read only
- Returns the path the URL of the
Fileis relative to.
Blob (en-US), so it also has the following properties available to it:
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
Blobobject containing the data in the specified range of bytes of the source
|File API||Working Draft||Initial definition|
BCD tables only load in the browser
- 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
- Starting from Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), privileged code (such as extensions) can pass an
nsIFileobject to the DOM
Fileconstructor to specify the file to reference.
- Starting from Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5), you can use
new Fileto create
Fileobjects from XPCOM component code instead of having to instantiate the
nsIDOMFileobject directly. The constructor takes, in contrast to
Blob(en-US), 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.getAsText(string encoding)(en-US) (błąd 661876). Standard properties
Blob.size(en-US), and methods on
FileReader(en-US) should be used instead.