FileReader: error event

The error event is fired when the read failed due to an error (for example, because the file was not found or not readable).

Bubbles No
Cancelable No
Interface ProgressEvent
Event handler property FileReader.onerror


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: ${}`);

        reader.addEventListener('load', () => {
            console.error(`File: ${} read successfully`);


fileInput.addEventListener('change', handleSelected);


Specification Status
File API Working Draft

Browser compatibility

BCD tables only load in the browser

See also