Dynamic Application API
readFile()
asyncProvides an interface that enables web applications to asynchronously read files or raw data buffers from the user's computer using File or Blob objects.
- Accepts a File or Blob object as its first argument.
-
Accepts an optional object as a second argument with the following properties:
PropertyTypeDescriptionprogressfunctionA function that accepts an argument containing an object with the following properties:PropertyTypeDescriptionloadednumberThe size of the data read in bytes.totalnumberTotal size of the data in bytes.percentnumberThe percentage of data downloaded or uploaded as a floating-point number.responsefunctionA function that accepts an argument containing the result of reading.errorfunctionA function that accepts an argument containing a reading error.
- It is not necessary to wait for the method to be executed using await if not needed.
-
Returns true when the read is successful.
Returns false on failure.
Example:
// Reading without processing the result.
readFile(File);
// Reading with result processing.
readFile(File, {
progress: (e) => {
$('#status').txt(`${e.loaded} / ${e.total}, ${e.percent}`);
},
response: (e) => {
$('#photo').src = e;
},
error: (e) => {
$('#status').txt(`Read error: ${e}`);
}
});
// Waits for the reading process to complete.
await readFile(File);