File
Baseline
Widely available
*
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
* Some parts of this feature may have varying levels of support.
Note: This feature is available in Web Workers.
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, or from a drag and drop operation's DataTransfer object.
A File object is a specific kind of Blob, and can be used in any context that a Blob can. In particular, the following APIs accept both Blobs and File objects:
FileReaderURL.createObjectURL()Window.createImageBitmap()andWorkerGlobalScope.createImageBitmap()- the
bodyoption tofetch() XMLHttpRequest.send()
See Using files from web applications for more information and examples.
Constructor
File()-
Returns a newly constructed
File.
Instance properties
The File interface also inherits properties from the Blob interface.
File.lastModifiedRead only-
Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).
File.lastModifiedDateRead only-
Returns the last modified
Dateof the file referenced by theFileobject. File.nameRead only-
Returns the name of the file referenced by the
Fileobject. File.webkitRelativePathRead only-
Returns the path the URL of the
Fileis relative to.
Instance methods
The File interface also inherits methods from the Blob interface.
Specifications
| Specification |
|---|
| File API # file-section |
Browser compatibility
| desktop | mobile | server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
File
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File() constructor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastModified
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lastModifiedDate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
webkitRelativePath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- Non-standard. Check cross-browser support before using.
- Deprecated. Not for use in new websites.
- See implementation notes.
- Has more compatibility info.