FileReader object
The FileReader object provides methods to asynchronously read a File or Blob, and events to obtain the results of these reads.
![]() |
Syntax
var reader = new FileReader();
DOM Information
Inheritance Hierarchy
The FileReader does not inherit from any class or interface.Members
The FileReader object has these types of members:
Events
The FileReader object has these events.
| Event | Description |
|---|---|
| onabort |
ProgressEvent that occurs when a read or creation operation is aborted by calling the abort method. |
| onerror |
ProgressEvent that fires when an error occurs during a read operation by an MSStreamReader or FileReader object. |
| onload |
ProgressEvent that occurs when a read operation by an MSStreamReader or FileReader object successfully completes. |
| onloadend |
ProgressEvent that occurs when a read operation by an MSStreamReader or FileReader object completes, even if the request fails. |
| onloadstart |
ProgressEvent that occurs when a read operation is started by an MSStreamReader or FileReader object. |
| onprogress |
ProgressEvent that occurs when an MSStreamReader or FileReader object reports progress about a read operation. |
Methods
The FileReader object has these methods.
| Method | Description |
|---|---|
| abort |
Aborts a read operation by an MSStreamReader or FileReader object. |
| readAsArrayBuffer |
Reads a File, Blob, MSStream into memory as an ArrayBuffer object. |
| readAsBinaryString | |
| readAsDataURL |
Reads a File or Blob object into memory as a data URL string. |
| readAsText |
Reads a File, Blob, or MSStream object into memory as a text string. |
Properties
The FileReader object has these properties.
| Property | Access type | Description |
|---|---|---|
|
Read-only |
The error that occurred while reading a File, Blob, or MSStream object. | |
|
Contains a constant indicating the current state of the FileReader or MSStreamReader object. | ||
|
The result of the read operation. |
Remarks
The FileReader constructor returns a new FileReader object.
The FileReader object enables asynchronous reads on individual File or Blob objects by firing progress events as the read occurs to event handler methods attached to the FileReader object.
A read operation will fail if a File or Blob is closed using the msClose method while the read operation is in progress.
Examples
var reader = new FileReader(); // Setup callback functions: reader.onprogress = updateProgress; reader.onload = loaded; reader.onerror = errorHandler; // Read file into memory as UTF-8: reader.readAsText(readFile, "UTF-8");
