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 Blob
s and File
s.
See Using files from web applications for more information and examples.
File()
File
.File.lastModified
Read only
File.lastModifiedDate
Read only Date
Date
of the file referenced by the File
object.File.name
Read only
File
object.File.webkitRelativePath
Read only
File
is relative to.File
implements Blob
, so it also has the following properties available to it:
File.size
Read only
File.type
Read only
The File
interface doesn't define any methods, but inherits methods from the Blob
interface:
Blob.slice([start[, end[, contentType]]])
Blob
object containing the data in the specified range of bytes of the source Blob
.Specification | Status | Comment |
---|---|---|
File API | Working Draft | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 13 | Yes | 7
|
10 | 11.5 | 6 |
File() constructor |
13 | No | 7 | No | 11.5 | 10.1 |
lastModified |
13 | 18 | 15 | 10 | 16 | No |
lastModifiedDate
|
13 | 12 | 15 — 61 | 10 | 16 | No |
name |
13 | 12 | 3.6 | 10 | 16 | Yes |
type |
13 | Yes | 3.6 | 10 | 16 | Yes |
webkitRelativePath |
13
|
No | 49 | No | No | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | 7
|
11.1 | 6 | Yes |
File() constructor |
Yes | Yes | Yes | 7 | No | 6 | 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 |
webkitRelativePath |
Yes | 18
|
No | 49 | No | No | ? |
Cu.importGlobalProperties(['File']);
nsIFile
object to the DOM File
constructor to specify the file to reference.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 );
File.fileName
, File.fileSize
, File.getAsBinary()
, File.getAsDataURL()
, File.getAsText(string encoding)
(bug 661876). Standard properties File.name
, Blob.size
, and methods on FileReader
should be used instead.FileReader
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/File