--- title: File slug: Web/API/File tags: - API - DOM - Files translation_of: Web/API/File --- <div>{{APIRef }}</div> <p>Das<strong><code>File</code></strong> Interface stellt Informationen über Dateien bereit und erlaubt den Zugriff auf deren Inhalt.</p> <p><code>File</code> werden generell von einem {{domxref("FileList")}} Objekt als das Ergebnis einer Benutzerauswahl von Dateien über ein <code>{{ HTMLElement("input") }}</code> Element, von einem <a href="/en-US/docs/DragDrop/DataTransfer" title="DragDrop/DataTransfer"><code>DataTransfer</code></a> Objekt eines Drag-and-Drop-Vorgangs,<span style="line-height: 1.5;"> oder von der </span><code style="font-size: 14px;">mozGetAsFile()</code><span style="line-height: 1.5;"> API eines {{ domxref("HTMLCanvasElement") }} zurückgegeben</span><span style="line-height: 1.5;">. In Gecko ist es von privilegiertem Code aus möglich, den Konstruktor direkt mit einem String Pfad oder einem {{interface("nsIFile")}} aufzurufen. Siehe <a href="/en-US/docs/Extensions/Using_the_DOM_File_API_in_chrome_code" title="Using the DOM File API in chrome code">Using the DOM File API in chrome code</a> für weitere Details.</span></p> <p>Die Dateireferenz kann nach der Formularübermittlung gespeichert werden, während der Benutzer über keine Internetverbindung verfügt. Somit können die Daten empfangen und hochgeladen werden, sobald die Internetverbindung wiederhergestellt ist.</p> <h2 id="Properties" name="Properties">Properties</h2> <p><em>Das<code>File</code> Interface erbt ebenso von dem {{domxref("Blob")}} Interface.</em></p> <dl> <dt>{{domxref("File.lastModifiedDate")}} {{readonlyinline}} {{gecko_minversion_inline("15.0")}}</dt> <dd>Das <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date">Date</a></code> der letzten Veränderung der Datei, referenziert durch das <code>File</code> Objekt.</dd> <dt>{{domxref("File.name")}} {{readonlyinline}} {{gecko_minversion_inline("1.9.2")}}</dt> <dd>Der Name der Datei, referenziert durch das <code>File</code> Objekt.</dd> <dt>{{domxref("File.fileName")}} {{non-standard_inline}} {{readonlyinline}} {{obsolete_inline("7.0")}}</dt> <dd>Der Name der Datei, referenziert durch das <code>File</code> Objekt.</dd> <dt>{{domxref("File.fileSize")}} {{non-standard_inline}} {{readonlyinline}} {{obsolete_inline("7.0")}}</dt> <dd>Die Größe der Datei in Bytes.</dd> </dl> <h2 id="Method_overview" name="Method_overview">Methods</h2> <p><em>The <code>File</code> interface also inherits methods from the {{domxref("Blob")}} interface.</em></p> <dl> <dt>{{domxref("File.getAsBinary()")}} {{non-standard_inline}} {{obsolete_inline("7.0")}}</dt> <dd>Returns a string containing the file's data in raw binary format.</dd> <dt>{{domxref("File.getAsDataURL()")}} {{non-standard_inline}} {{obsolete_inline("7.0")}}</dt> <dd>A string containing the file's data encoded as a <code>data:</code> URL.</dd> <dt>{{domxref("File.getAsText()","File.getAsText(string encoding)")}} {{non-standard_inline}} {{obsolete_inline("7.0")}}</dt> <dd>Returns the file's contents as a string in which the file's data is interpreted as text using a given encoding.</dd> </dl> <h2 id="Browser_Compatibility" name="Browser_Compatibility">Specifications</h2> <table class="standard-table"> <tbody> <tr> <th scope="col">Specification</th> <th scope="col">Status</th> <th scope="col">Comment</th> </tr> <tr> <td>{{SpecName('File API')}}</td> <td>{{Spec2('File API')}}</td> <td>Initial definition.</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2> <div>{{CompatibilityTable}}</div> <div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>13</td> <td>{{CompatGeckoDesktop("1.9")}} (non standard)<br> {{CompatGeckoDesktop("7")}} (standard)</td> <td>10.0</td> <td>11.5</td> <td>6.0</td> </tr> </tbody> </table> </div> <div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>basic support</td> <td>{{CompatNo}}</td> <td>25</td> <td>{{CompatNo}}</td> <td>11.1</td> <td>6.0</td> </tr> </tbody> </table> </div> <h3 id="Specification" name="Specification">Implementation notes</h3> <h4 id="Gecko_notes">Gecko notes</h4> <ul> <li>In Gecko, you can use this API from chrome code. See <a href="/en-US/docs/Extensions/Using_the_DOM_File_API_in_chrome_code" title="Using the DOM File API in chrome code">Using the DOM File API in chrome code</a> for details.</li> <li>Starting in Gecko 6.0 {{geckoRelease("6.0")}}, privileged code (such as extensions) can pass an {{interface("nsIFile")}} object to the DOM <code>File</code> constructor to specify the file to reference.</li> <li>Starting in Gecko 8.0 {{geckoRelease("8.0")}}, you can use <code>new File</code> to create <code>File</code> objects from XPCOM component code instead of having to instantiate the {{interface("nsIDOMFile")}} object directly. The constructor takes, in contrast to Blob, as second argument the filename. The filename can be any String. <pre class="syntaxbox">File File( Array parts, String filename, BlobPropertyBag properties );</pre> </li> </ul> <h2 id="Chrome_Code_-_Scope_Availability">Chrome Code - Scope Availability</h2> <p>To use from chrome code, JSM and Bootstrap scope, you have to import it like this:</p> <pre class="brush: js">Cu.importGlobalProperties(['File']); </pre> <p><code>URL</code> is available in Worker scopes.</p> <h2 id="See_also" name="See_also">See also</h2> <ul> <li><a href="/en-US/docs/Using_files_from_web_applications" title="Using files from web applications">Using files from web applications</a></li> <li><a href="/en-US/docs/Extensions/Using_the_DOM_File_API_in_chrome_code" title="Extensions/Using the DOM File API in chrome code">Using the DOM File API in chrome code</a></li> <li>{{domxref("FileReader")}}</li> <li><a href="/en-US/docs/Components.utils.importGlobalProperties">Components.utils.importGlobalProperties</a></li> </ul>