Provides methods to read the File or the Blob objects into memory, and to access the data from those objects with a usage of progress events and event handler attributes.
The result
attribute returns the Blob object
data in a form of DOMString
, ArrayBuffer
, or null, depending on the
read method that has been called on the FileReader object,
and errors that may have occurred. It can also return partial Blob data. Partial Blob data is
the part of the File object or the Blob object that has been read into memory currently. When
processing the readAsText method, the partial Blob data is a DOMString
that is incremented as more
bytes are loaded, and when processing the readAsArrayBuffer method the partial Blob data is an
ArrayBuffer
object instance that consists of the bytes loaded so far.
If readyState
is 'empty', i.e. no read method has been called, then the
result
attribute returns null.
If an error in reading the File or the Blob objects has occurred with usage of any read method, then
the result
attribute returns null.
If the readAsDataURL method is used, the
result
attribute returns a DOMString
that is a Data URL
encoding of the File or the Blob object data.
If the readAsText method is called and no error in
reading the File or the Blob objects has occurred, then the result attribute returns a
string
representing the File or the Blob objects data in the format specified by the encoding
determination. While processing the readAsText method,
this result
returns partial Blob data in the
format specified by the encoding determination as a DOMString
that is
incremented as more data is read.
If the readAsArrayBuffer method is called and no
error in reading the File or the Blob objects has occurred, then the result
attribute returns an ArrayBuffer
object instance. While processing the readAsArrayBuffer method, the result
attribute
returns partial Blob data in a form of
ArrayBuffer
.
Event handler attribute | Event type | Description |
---|---|---|
onloadstart | loadstart | When the read starts. |
onprogress | progress | While reading and decoding the Blob, and reporting partial the Blob data (progess.loaded/progress.total). |
onabort | abort | When the read has been aborted. For instance, by invoking the abort method. |
onerror | error | When the read has failed. |
onload | load | When the read has successfully completed. |
onloadend | loadend | When the request has completed: either in success or failure. |
The readyState
attribute returns the current state of the FileReader object, which takes one of the following
values:
State | Description | Value |
---|---|---|
Empty | The FileReader object has been constructed, and there are no pending reads. None of the read methods have been called. This is the default state of a newly minted FileReader object, until one of the read methods have been called on it. | 0 |
Loading | The File or the Blob object is being read. One of the read methods is being processed, and no error has occurred during the read. | 1 |
Done | The entire File or Blob object has been read into memory, a file
error occurred during the read or the read was aborted using the abort method. If readyState attribute
is set to 'Done' it means that at least one of the read methods have been called on this
FileReader object. |
2 |
Name | Description |
---|---|
abort | Terminates the algorithm for the currently executed method. |
readAsArrayBuffer | Returns the read data as the ArrayBuffer object. |
readAsDataURL | Returns the read data as an URL. |
readAsText | Returns the read data as a text string. |