--- 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")}}.
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
.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
.File
into a {{DOMxRef("ReadableStream")}} that can be used to read the File
contents.File
into a stream and reads it to completion. It returns a promise that resolves with a {{DOMxRef("USVString")}} (text).File
into a stream and reads it to completion. It returns a promise that resolves with an {{DOMxRef("ArrayBuffer")}}.Specification | Status | Comment |
---|---|---|
{{SpecName('File API', "#file-section", "The File interface")}} |
{{Spec2('File API')}} | Initial definition. |
{{Compat("api.File")}}