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

Examples

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.error(`File: ${selectedFile.name} read successfully`);
        });

        reader.readAsDataURL(selectedFile);
    }
}

fileInput.addEventListener('change', handleSelected);

Specifications

Specification
File API
# dfn-error-event

Browser compatibility

BCD tables only load in the browser

See also