FileError object
[Internet Explorer 10. This object was supported in pre-release versions of Internet Explorer 10. As of Internet Explorer 10, it is obsolete and DOMError should be used instead. Applications using this object should be updated accordingly.]
The FileError object reports file-related errors asynchronously.
![]() |
Syntax
if (evt.target.error.name == "NotReadableError") { document.write("File could not be read."); }
DOM Information
Inheritance Hierarchy
The FileError does not inherit from any class or interface.Members
The FileError object has these types of members:
Properties
The FileError object has these properties.
| Property | Access type | Description |
|---|---|---|
|
Read-only |
Note
Internet Explorer 10. This object was supported in pre-release versions of Internet Explorer 10. As of Internet Explorer 10,
it is obsolete and DOMError should be used instead. Applications using this object should be updated
accordingly.
|
Remarks
The FileReader object's error property is a
FileError object and is accessed asynchronously through the
onerror event handler when error events are generated. The
FileError object's code property and associated error codes allow asynchronous file error handling, as suggested in the following example.
Examples
The following example shows how to use the code property and file error codes.
<!DOCTYPE html> <html> <head> <title>File Errors</title> <style type="text/css"> #alert { color: red; margin: 1em 0; } </style> <script type="text/javascript"> window.addEventListener('load', init, false); function init() { checkForFileApiSupport(); document.getElementById('fileInput').addEventListener('change', startRead, false); } function checkForFileApiSupport() { if (window.File && window.FileReader && window.FileList && window.Blob) { // All the File APIs are supported. } else { document.getElementById('alert').innerHTML = "The File APIs are not fully supported in this browser."; } } function startRead() { // Obtain the file associated with the <input> element through the DOM. var file = document.getElementById('fileInput').files[0]; if (file) { getAsText(file); } else { document.getElementById('alert').innerHTML = "file = " + file; } } function getAsText(readFile) { var reader = new FileReader(); // Handle progress, success, and errors: reader.onprogress = updateProgress; reader.onload = loaded; reader.onerror = errorHandler; reader.readAsText(readFile, "UTF-8"); } function updateProgress(evt) { if (evt.lengthComputable) { var loaded = (evt.loaded / evt.total); // evt.loaded and evt.total are ProgressEvent properties. if (loaded < 1) { // Increase the progress bar length. } } } function loaded(evt) { // Obtain the file data which was read into memory: var fileString = evt.target.result; // xhr.send(fileString) document.getElementById('alert').innerHTML = '<span style="color: black;">' + fileString + '</span>'; } function errorHandler(evt) { switch (evt.target.error.name) { case "NotFoundError": // The File or Blob could not be found at the time the read was processed. break; case "SecurityError": // An error not covered by other error codes occured including: // * Certain files are unsafe for access within a web application. // * Too many read calls are being made on File or Blob resources. // * The file has changed on disk since the user selected it. break; case "AbortError": // The read operation was aborted, typically with a call to abort(). break; case "NotReadableError": // The File or Blob cannot be read, typically due due to permission problems that occur after a reference to a File or Blob has been acquired (concurrent lock with another application). break; case "EncodingError": // The length of the data URL for a File or Blob is too long. break; default: document.getElementById('alert').innerHTML = "File error code: " + evt.target.error.name; } } </script> </head> <body> <input id="fileInput" type="file" /> <div id="alert"><!-- Fills the roll of alert(). --></div> </body> </html>
