Visit Mozilla.org

nsIDOMFile

From MDC

This article covers features introduced in Firefox 3

The nsIDOMFile interface retrieves data from a file submitted to a form using the input type "file". This allows the file reference to be saved when the form is submitted while the user is using a web application offline, so that the data can be retrieved and uploaded once the Internet connection is restored.

Note: All of the methods in this interface can raise an nsIDOMFileException if an error occurs.

Contents

nsIDOMFile is defined in content/base/public/nsIDOMFile.idl. It is scriptable and unfrozen (hasn't changed since Mozilla 1.9).

Inherits from: nsISupports

[edit] Method overview

DOMString getAsBinary();
DOMString getAsDataURL();
DOMString getAsText(in DOMString encoding);

[edit] Attributes

Attribute Type Description
fileName DOMString A read-only attribute containing the name of the file referenced by the nsIDOMFile object.
fileSize unsigned long long The size of the referenced file in bytes.

[edit] Methods

[edit] getAsBinary()

Returns a DOMString containing the file's data in raw binary format.

 DOMString getAsBinary();
[edit] Parameters

None.

[edit] Return value

A DOMString containing the raw binary contents of the file.

[edit] getAsDataURL()

Returns a DOMString containing a data: URL that encodes the entire contents of the referenced file.

 DOMString getAsDataURL();
[edit] Parameters

None.

[edit] Return value

An DOMString containing the file's data encoded as a data: URL.

[edit] getAsText()

Returns the file's contents as a DOMString in which the file's data is interpreted as text using a given encoding.

 DOMString getAsText(
   in DOMString encoding
 );
[edit] Parameters
encoding
A string indicating the encoding to use for the returned data. If this string is empty, UTF-8 is assumed.
[edit] Return value

An DOMString containing the file's data interpreted as text in the specified encoding.

[edit] See also

nsIDOMFileList, nsIDOMFileException