FileReader object

3 out of 4 rated this helpful - Rate this topic

A constructor function producing an object that provides methods to asynchronously read a File or a Blob, and an event model 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.

EventDescription
onabort

Fires when a read or creation operation is aborted by calling the abort method.

onerror

Fires when an error occurs when using the msStreamReader or FileReader object.

onload

Fires when the creation of, or read by, an msStreamReader or FileReader object successfully completes.

onloadend

Fires when the request to create or read an msStreamReader or FileReader object completes, even if the request fails.

onloadstart

Fires at the start of the creation of, or read by, an msStreamReader or FileReader object.

onprogress

Contains a function pointer to the onprogress event handler (callback) function.

 

Methods

The FileReader object has these methods.

MethodDescription
abort

Aborts a read operation by an MSStreamReader or FileReader object.

readAsArrayBuffer

Reads a File or Blob into memory as an array buffer.

readAsDataURL

Reads a File or Blob into memory as a data URL string.

readAsText

Reads a File or Blob into memory as a text string.

 

Properties

The FileReader object has these properties.

PropertyDescription

error

The error that occurred while reading the file.

readyState

Contains a constant indicating the current state of the FileReader/msStreamReader object.

result

The result of the read operation.

 

Remarks

When the FileReader constructor is invoked, a new FileReader object is returned. This 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.

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");  

 

 

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.