files/en-us/web/api/filereader/error_event/index.md
{{APIRef("File API")}}{{AvailableInWorkers}}
The error event of the {{domxref("FileReader")}} interface is fired when the read failed due to an error (for example, because the file was not found or not readable).
This event is not cancelable and does not bubble.
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("error", (event) => { })
onerror = (event) => { }
A {{domxref("ProgressEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("ProgressEvent")}}
Also inherits properties from its parent {{domxref("Event")}}.
total by the value of this property. When downloading a resource using HTTP, this only counts the body of the HTTP message, and doesn't include headers and other overhead.Content-Length (the size of the body of the message), and doesn't include the headers and other overhead.const fileInput = document.querySelector('input[type="file"]');
const reader = new FileReader();
function handleSelected(e) {
const selectedFile = fileInput.files[0];
if (selectedFile) {
reader.addEventListener("error", () => {
console.error(`Error occurred reading file: ${selectedFile.name}`);
});
reader.addEventListener("load", () => {
console.log(`File: ${selectedFile.name} read successfully`);
});
reader.readAsDataURL(selectedFile);
}
}
fileInput.addEventListener("change", handleSelected);
{{Specifications}}
{{Compat}}