--- title: File slug: Web/API/File tags: - API - File API - Interface - NeedsTranslation - Reference - TopicStub - Web translation_of: Web/API/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 {{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 |
{{Compat("api.File")}}
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 );