This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
Expo FileSystem
A library that provides access to the local file system on the device.
expo-file-system provides access to files and directories stored on a device or bundled as assets into the native project. It also allows downloading files from the network.
Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
Configuration in app config
You can configure expo-file-system using its built-in config plugin if you use config plugins in your project (Continuous Native Generation (CNG)). The plugin allows you to configure various properties that cannot be set at runtime and require building a new app binary to take effect. If your app does not use CNG, then you'll need to manually configure the library.
Example app.json with config plugin
Configurable properties
Are you using this library in an existing React Native app?
If you're not using Continuous Native Generation (CNG) or you're using native ios project manually, then you need to add the LSSupportsOpeningDocumentsInPlace and UIFileSharingEnabled keys to your project's ios/[app]/Info.plist:
<key>LSSupportsOpeningDocumentsInPlace</key> <true/> <key>UIFileSharingEnabled</key> <true/>
Usage
import { File, Directory, Paths } from 'expo-file-system';
The File and Directory instances hold a reference to a file, content, or asset URI.
The file or directory does not need to exist — an error will be thrown from the constructor only if the wrong class is used to represent an existing path (so if you try to create a File instance passing a path to an already existing directory).
Features
- Both synchronous and asynchronous, read and write access to file contents
- Creation, modification and deletion
- Available properties, such as
type,size,creationDate, and more - Ability to read and write files as streams or using the
FileHandleclass - Easy file download/upload using
downloadFileAsyncorexpo/fetch - File previews using platform-native flows
Examples
Picking files using system pickers
Usage with expo-document-picker:
Using the built-in pickFileAsync or pickDirectoryAsync method on Android:
Previewing files
Use File.preview() to open local files in the native viewer. Android opens an installed
app that supports the file's MIME type. iOS uses Quick Look.
File.preview() and File.canPreview() accept a File or an ordered File[].
For one file, you can also call file.preview() and file.canPreview() directly.
Multiple files are supported on iOS only. This example opens the notes first and lets the user navigate to the PDF:
initialIndex is zero-based and defaults to 0. An array with one file works on
both platforms. On Android, passing multiple files makes File.canPreview()
resolve to false and File.preview() reject.
File.preview() rejects if you pass title or mimeType with multiple files.
File.canPreview() rejects if you pass mimeType with multiple files.
For a single file, mimeType defaults to the file's type. Pass it explicitly
if the extension does not identify the type, particularly on Android.
File.canPreview() resolves to false when the platform cannot preview, or when
a checked file is missing or has an unsupported type. It rejects if it encounters
an invalid or unreadable file. File.preview() rejects if any file cannot be
previewed or initialIndex is invalid. Both methods reject empty arrays.
Keep files available until the viewer closes. File.preview() resolves when the
preview is presented or handed off to another app.
If a share sheet is useful in your app, you can compose this with expo-sharing when previewing fails:
Uploading files using expo/fetch
You can upload files as blobs directly with fetch built into the Expo package:
Or using the FormData constructor:
Random-access reads with FileHandle
Use FileHandle for efficient, random-access reads of large files without loading the entire file into memory. Obtain a handle by calling file.open(), read or write at any position using the offset property, and always close the handle when finished.
API
No API data file found, sorry!