FileReader

The FileReader interface lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read.

MDN Reference

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed interface ReadyState

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The error read-only property of the FileReader interface returns the error that occurred while reading the file.

Link copied to clipboard
Link copied to clipboard

The readyState read-only property of the FileReader interface provides the current state of the reading operation. This will be one of the states: EMPTY, LOADING, or DONE.

Link copied to clipboard

The result read-only property of the FileReader interface returns the file's contents. This property is only valid after the read operation is complete, and the format of the data depends on which of the methods was used to initiate the read operation.

Functions

Link copied to clipboard
fun abort()

The abort() method of the FileReader interface aborts the read operation. Upon return, the readyState will be DONE.

Link copied to clipboard
fun <E : Event> EventTargetLike.addEventListener(type: EventType<E>, handler: (E) -> Unit, options: AddEventListenerOptions? = undefined)

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

Link copied to clipboard
open fun dispatchEvent(event: Event): Boolean

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

Link copied to clipboard

The readAsArrayBuffer() method of the FileReader interface is used to start reading the contents of a specified Blob or File. When the read operation is finished, the readyState property becomes DONE, and the loadend event is triggered. At that time, the result property contains an ArrayBuffer representing the file's data.

Link copied to clipboard
fun readAsDataURL(blob: Blob)

The readAsDataURL() method of the FileReader interface is used to read the contents of the specified Blob or File. When the read operation is finished, the readyState property becomes DONE, and the loadend event is triggered. At that time, the result attribute contains the data as a data: URL representing the file's data as a base64 encoded string.

Link copied to clipboard
fun readAsText(blob: Blob, encoding: String = definedExternally)

The readAsText() method of the FileReader interface is used to read the contents of the specified Blob or File. When the read operation is complete, the readyState property is changed to DONE, the loadend event is triggered, and the result property contains the contents of the file as a text string.

Link copied to clipboard
fun <E : Event> EventTargetLike.removeEventListener(type: EventType<E>, handler: (E) -> Unit, options: EventListenerOptions? = undefined)

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

Link copied to clipboard
fun <T : Event> when(type: EventType<T>, options: ObservableEventListenerOptions? = definedExternally): Observable<T>