DasFile
Interface stellt Informationen über Dateien bereit und erlaubt den Zugriff auf deren Inhalt.
File
werden generell von einem FileList
Objekt als das Ergebnis einer Benutzerauswahl von Dateien über ein
Element, von einem <input>
DataTransfer
Objekt eines Drag-and-Drop-Vorgangs, oder von der mozGetAsFile()
API eines HTMLCanvasElement
zurückgegeben. In Gecko ist es von privilegiertem Code aus möglich, den Konstruktor direkt mit einem String Pfad oder einem nsIFile
aufzurufen. Siehe Using the DOM File API in chrome code für weitere Details.
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.
Properties
DasFile
Interface erbt ebenso von dem Blob
Interface.
File.lastModifiedDate
Read only- Das
Date
der letzten Veränderung der Datei, referenziert durch dasFile
Objekt. File.name
Read only- Der Name der Datei, referenziert durch das
File
Objekt. File.fileName
Read only Veraltet seit Gecko 7.0- Der Name der Datei, referenziert durch das
File
Objekt. File.fileSize
Read only Veraltet seit Gecko 7.0- Die Größe der Datei in Bytes.
Methods
The File
interface also inherits methods from the Blob
interface.
File.getAsBinary()
Veraltet seit Gecko 7.0- Returns a string containing the file's data in raw binary format.
File.getAsDataURL()
Veraltet seit Gecko 7.0- A string containing the file's data encoded as a
data:
URL. File.getAsText(string encoding)
Veraltet seit Gecko 7.0- Returns the file's contents as a string in which the file's data is interpreted as text using a given encoding.
Specifications
Specification | Status | Comment |
---|---|---|
File API | Arbeitsentwurf | Initial definition. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 13 | 3.0 (1.9) (non standard) 7 (7) (standard) |
10.0 | 11.5 | 6.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
basic support | Nicht unterstützt | 25 | Nicht unterstützt | 11.1 | 6.0 |
Implementation notes
Gecko notes
- In Gecko, you can use this API from chrome code. See Using the DOM File API in chrome code for details.
- Starting in Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), privileged code (such as extensions) can pass an
nsIFile
object to the DOMFile
constructor to specify the file to reference. - Starting in Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5), you can use
new File
to createFile
objects from XPCOM component code instead of having to instantiate thensIDOMFile
object directly. The constructor takes, in contrast to Blob, as second argument the filename. The filename can be any String.File File( Array parts, String filename, BlobPropertyBag properties );
Chrome Code - Scope Availability
To use from chrome code, JSM and Bootstrap scope, you have to import it like this:
Cu.importGlobalProperties(['File']);
URL
is available in Worker scopes.