--- title: File slug: Web/API/File translation_of: Web/API/File ---
ONGOING 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 {{domxref("FileList")}} object returned as a result of a user selecting files using the {{HTMLElement("input")}} element, from a drag and drop operation's {{domxref("DataTransfer")}} object, or from the mozGetAsFile()
API on an {{domxref("HTMLCanvasElement")}}. In Gecko, privileged code can create File
objects representing any local file without user interaction (see {{anch("Implementation notes")}} for more information.)
A File
object is a specific kind of a {{domxref("Blob")}}, and can be used in any context that a Blob can. In particular, {{domxref("FileReader")}}, {{domxref("URL.createObjectURL()")}}, {{domxref("ImageBitmapFactories.createImageBitmap()", "createImageBitmap()")}}, and {{domxref("XMLHttpRequest", "", "send()")}} accept both Blob
s and File
s.
See Using files from web applications for more information and examples.
{{InheritanceDiagram}}
File
.Date
of the file referenced by the File
object.File
object.File
implements {{domxref("Blob")}}, so it also has the following properties available to it:
The File
interface doesn't define any methods, but inherits methods from the {{domxref("Blob")}} interface:
Blob
object containing the data in the specified range of bytes of the source Blob
.Specification | Status | Comment |
---|---|---|
{{SpecName('File API')}} | {{Spec2('File API')}} | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 13 | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9")}}[1] {{CompatGeckoDesktop("7")}} |
10.0 | 11.5 | 6.0 |
name |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.9.2")}} | 11.0 | {{CompatUnknown}} | {{CompatUnknown}} |
lastModifiedDate {{deprecated_inline}} |
{{CompatUnknown}} | {{CompatNo}} | {{CompatGeckoDesktop("15")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
webkitRelativePath {{non-standard_inline}} |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("49")}} | {{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
size | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | 11.0 | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Edge | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.9")}}[1] {{CompatGeckoMobile("7")}} |
{{CompatNo}} | 11.1 | 6.0 |
name |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.9.2")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
lastModifiedData {{deprecated_inline}} |
{{CompatUnknown}} | {{CompatNo}} | {{CompatGeckoMobile("15")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
webkitRelativePath {{non-standard_inline}} |
{{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoMobile("49")}} | {{CompatUnknown}} | {{CompatVersionUnknown}} |
{{CompatVersionUnknown}} |
size | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
[1] Non-standard implementation.
Cu.importGlobalProperties(['File']);
File
constructor to specify the file to reference.new File
to create File
objects from XPCOM component code instead of having to instantiate the {{interface("nsIDOMFile")}} object directly. The constructor takes, in contrast to {{domxref("Blob")}}, as second argument the filename. The filename can be any String.
new File( Array parts, String filename, BlobPropertyBag properties );