File

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.

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.

Constructor

File()
Returns a newly constructed File.

Instance properties

File.prototype.lastModified Read only
Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).
File.prototype.lastModifiedDate Read only
Returns the last modified Date of the file referenced by the File object.
File.prototype.nameRead only
Returns the name of the file referenced by the File object.
File.prototype.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.prototype.size Read only
Returns the size of the file in bytes.
File.prototype.type Read only
Returns the MIME type of the file.

Instance methods

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

Blob.prototype.slice([start[, end[, contentType]]])
Returns a new Blob object containing the data in the specified range of bytes of the source Blob.
Blob.prototype.stream()
Transforms the File into a ReadableStream that can be used to read the File contents.
Blob.prototype.text()
Transforms the File into a stream and reads it to completion. It returns a promise that resolves with a USVString (text).
Blob.prototype.arrayBuffer()
Transforms the File into a stream and reads it to completion. It returns a promise that resolves with an ArrayBuffer.

Specifications

Specification Status Comment
File API
The definition of 'The File interface' in that specification.
Working Draft Initial definition.

Browser compatibility

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
FileChrome Full support 13Edge Full support 12Firefox Full support 7
Full support 7
No support 3 — 7
Notes
Notes Non-standard implementation.
IE Full support 10Opera Full support 11.5Safari Full support 6WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 7
Full support 7
No support 4 — 7
Notes
Notes Non-standard implementation.
Opera Android Full support 11.5Safari iOS Full support 6Samsung Internet Android Full support 1.0
File() constructorChrome Full support 13Edge Full support 79Firefox Full support 7IE No support NoOpera Full support 11.5Safari Full support 10.1WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 7Opera Android Full support 11.5Safari iOS Full support 6Samsung Internet Android Full support 1.0
lastModifiedChrome Full support 13Edge Full support 18Firefox Full support 15IE No support NoOpera Full support 16Safari Full support 10WebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support 10Samsung Internet Android Full support Yes
lastModifiedDate
DeprecatedNon-standard
Chrome Full support 13Edge Full support 12Firefox No support 15 — 61IE Full support 10Opera Full support 16Safari No support NoWebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
nameChrome Full support 13Edge Full support 12Firefox Full support 3.6IE Full support 10Opera Full support 16Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
typeChrome Full support 13Edge Full support 12Firefox Full support 3.6IE Full support 10Opera Full support 16Safari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes
webkitRelativePathChrome Full support 13
Prefixed
Full support 13
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Edge Full support 13Firefox Full support 49IE No support NoOpera No support NoSafari Full support 11.1WebView Android Full support YesChrome Android Full support 18
Prefixed
Full support 18
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android Full support 49Opera Android No support NoSafari iOS Full support 11.3Samsung Internet Android Full support 1.0
Prefixed
Full support 1.0
Prefixed
Prefixed Implemented with the vendor prefix: webkit

Legend

Full support
Full support
No support
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

See also