| title | FileSystemFileHandle: getFile() method |
|---|---|
| short-title | getFile() |
| slug | Web/API/FileSystemFileHandle/getFile |
| page-type | web-api-instance-method |
| browser-compat | api.FileSystemFileHandle.getFile |
{{securecontext_header}}{{APIRef("File System API")}}{{AvailableInWorkers}}
The getFile() method of the
{{domxref("FileSystemFileHandle")}} interface returns a {{jsxref('Promise')}} which resolves to a
{{domxref('File')}} object representing the state on disk of the entry represented by the handle.
If the file on disk changes or is removed after this method is called, the returned {{domxref('File')}} object will likely be no longer readable.
getFile()
None.
A {{jsxref('Promise')}} which resolves to a {{domxref('File')}} object.
NotAllowedError{{domxref("DOMException")}}- : Thrown if the {{domxref('PermissionStatus.state')}} is not
grantedinreadmode.
- : Thrown if the {{domxref('PermissionStatus.state')}} is not
NotFoundError{{domxref("DOMException")}}- : Thrown if current entry is not found.
The following asynchronous function presents a file picker and once a file is chosen,
uses the getFile() method to retrieve the contents.
async function getTheFile() {
// open file picker
const [fileHandle] = await window.showOpenFilePicker(pickerOpts);
// get file contents
const fileData = await fileHandle.getFile();
}{{Specifications}}
{{Compat}}