Get to know MDN better
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The File System API — with extensions provided via the File System Access API to access files on the device file system — allows read, write and file management capabilities.
See Relationship to other file-related APIs for a comparison between this API, the File and Directory Entries API, and the File API.
This API allows interaction with files on a user's local device, or on a user-accessible network file system. Core functionality of this API includes reading files, writing or saving files, and access to directory structure.
Most of the interaction with files and directories is accomplished through handles. A parent FileSystemHandle class helps define two child classes: FileSystemFileHandle and FileSystemDirectoryHandle, for files and directories respectively.
The handles represent a file or directory on the user's system. You can first gain access to them by showing the user a file or directory picker using methods such as window.showOpenFilePicker() and window.showDirectoryPicker(). Once these are called, the file picker presents itself and the user selects either a file or directory. Once this happens successfully, a handle is returned.
You can also gain access to file handles via:
Each handle provides its own functionality and there are a few differences depending on which one you are using (see the interfaces section for specific details). You then can access file data, or information (including children) of the directory selected. This API opens up potential functionality the web has been lacking. Still, security has been of utmost concern when designing the API, and access to file/directory data is disallowed unless the user specifically permits it (note that this is not the case with the Origin private file system, because it is not visible to the user).
Note: The different exceptions that can be thrown when using the features of this API are listed on relevant pages as defined in the spec. However, the situation is made more complex by the interaction of the API and the underlying operating system. A proposal has been made to list the error mappings in the spec, which includes useful related information.
Note: Objects based on FileSystemHandle can also be serialized into an IndexedDB database instance, or transferred via postMessage().
The origin private file system (OPFS) is a storage endpoint provided as part of the File System API, which is private to the origin of the page and not visible to the user like the regular file system. It provides access to a special kind of file that is highly optimized for performance and offers in-place write access to its content.
The following are some possible use cases:
Apps with persistent uploader
Video game or other apps with lots of media assets
Audio or photo editor with offline access or local cache (great for performance and speed)
Offline video viewer
Offline web mail client
Read our Origin private file system for instructions on how to use it.
Contains details of a single change observed by a FileSystemObserver.
FileSystemHandleAn object which represents a file or directory entry. Multiple handles can represent the same entry. For the most part you do not work with FileSystemHandle directly but rather its child interfaces FileSystemFileHandle and FileSystemDirectoryHandle.
FileSystemFileHandleProvides a handle to a file system entry.
FileSystemDirectoryHandleProvides a handle to a file system directory.
FileSystemObserverProvides a mechanism to observe changes to selected files or directories.
FileSystemSyncAccessHandleProvides a synchronous handle to a file system entry, which operates in-place on a single file on disk. The synchronous nature of the file reads and writes allows for higher performance for critical methods in contexts where asynchronous operations come with high overhead, e.g., WebAssembly. This class is only accessible inside dedicated Web Workers for files within the origin private file system.
FileSystemWritableFileStreamA WritableStream object with additional convenience methods, which operates on a single file on disk.
Displays a directory picker which allows the user to select a directory.
Window.showOpenFilePicker()Shows a file picker that allows a user to select a file or multiple files.
Window.showSaveFilePicker()Shows a file picker that allows a user to save a file.
DataTransferItem.getAsFileSystemHandle()Returns a Promise that fulfills with a FileSystemFileHandle if the dragged item is a file, or fulfills with a FileSystemDirectoryHandle if the dragged item is a directory.
StorageManager.getDirectory()Used to obtain a reference to a FileSystemDirectoryHandle object allowing access to a directory and its contents, stored in the origin private file system. Returns a Promise that fulfills with a FileSystemDirectoryHandle object.
The below code allows the user to choose a file from the file picker.
The following asynchronous function presents a file picker and once a file is chosen, uses the getFile() method to retrieve the contents.
The following example returns a directory handle with the specified name. If the directory does not exist, it is created.
The following asynchronous function uses resolve() to find the path to a chosen file, relative to a specified directory handle.
The following asynchronous function opens the save file picker, which returns a FileSystemFileHandle once a file is selected. A writable stream is then created using the FileSystemFileHandle.createWritable() method.
A user defined Blob is then written to the stream which is subsequently closed.
The following show different examples of options that can be passed into the write() method.
This example synchronously reads and writes a file to the origin private file system.
The following asynchronous event handler function is contained inside a Web Worker. On receiving a message from the main thread it:
Note: In earlier versions of the spec, close(), flush(), getSize(), and truncate() were unergonomically specified as asynchronous methods. This has now been amended, but some browsers still support the asynchronous versions.
| File System |
| File System Access |
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
Enable JavaScript to view this browser compatibility table.
This page was last modified on Oct 20, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.