FileReader.result
This property returns the contents of the file. This property is only valid after the read operation is completed, and the format of the data depends on the method for starting the read operation. FileReader
]**result**
syntax
var file = instanceOfFileReader .result
value
Or the appropriate string ArrayBuffer
] which to start reading method based on a read operation. This value is null
whether or not the reading has not been completed successfully.
The results of the following type.
method | description |
---|---|
readAsArrayBuffer() |
Of result the JavaScript ArrayBuffer binary data it contains. |
readAsBinaryString() |
The result contained in the original data file is a binary string. |
readAsDataURL() |
This result is a string data: URL transmitting data representation files. |
readAsText() |
This result is a text string. |
Case
This example shows a function, read()
the function reads the file from the file input. The way it works is to create an FileReader
object and creates a listener for the load event so that when reading the file result
acquired and passed to the callback function to provide read()
.
As the contents of the original text data processing.
var fileInput = document.querySelector('input[type="file"]');
function read(callback) {
var file = fileInput.files.item(0);
var reader = new FileReader();
reader.onload = function() {
callback(reader.result);
}
reader.readAsText(file);
}