Mozilla's getting a new look. What do you think? https://mzl.la/brandsurvey

File

Diese Übersetzung ist unvollständig. Bitte helfen Sie, diesen Artikel aus dem Englischen zu übersetzen.

The File interface provides information about files and allows to access their content.

These are generally retrieved from a FileList object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement. In Gecko, from privileged code it is possible to call the constructor directly with a string path or an nsIFile. See Using the DOM File API in chrome code for details.

The file reference can be saved when the form is submitted while the user is offline, so that the data can be retrieved and uploaded when the Internet connection is restored.

Properties

The File interface also inherits properties from the Blob interface.

File.lastModifiedDate Read only
The last modified Date of the file referenced by the File object.
File.name Read only
The name of the file referenced by the File object.
File.fileName Read only Veraltet seit Gecko 7.0
The name of the file referenced by the File object.
File.fileSize Read only Veraltet seit Gecko 7.0
The size of the referenced file 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 DOM File 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 create File objects from XPCOM component code instead of having to instantiate the nsIDOMFile 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.

See also

Schlagwörter des Dokuments und Mitwirkende

Schlagwörter: 
 Mitwirkende an dieser Seite: fscholz
 Zuletzt aktualisiert von: fscholz,