Expo FileSystem
A library that provides access to the local file system on the device.
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
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
- npx expo install expo-file-systemIf 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
{ "expo": { "plugins": [ [ "expo-file-system", { "supportsOpeningDocumentsInPlace": true, "enableFileSharing": true } ] ] } }
Configurable properties
| Name | Default | Description |
|---|---|---|
supportsOpeningDocumentsInPlace | false | Only for: iOS A boolean to enable |
enableFileSharing | false | Only for: iOS A boolean to enable |
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
Examples
Writing and reading text files
import { File, Paths } from 'expo-file-system'; try { const file = new File(Paths.cache, 'example.txt'); file.create(); // can throw an error if the file already exists or no permission to create it file.write('Hello, world!'); console.log(file.textSync()); // Hello, world! } catch (error) { console.error(error); }
Picking files using system pickers
Usage with expo-document-picker:
import { File } from 'expo-file-system'; import * as DocumentPicker from 'expo-document-picker'; try { const result = await DocumentPicker.getDocumentAsync({ copyToCacheDirectory: true }); if (!result.canceled) { const { uri } = result.assets[0]; const file = new File(uri); console.log(file.textSync()); } } catch (error) { console.error(error); }
Using the built-in pickFileAsync or pickDirectoryAsync method on Android:
import { File } from 'expo-file-system'; try { const file = new File.pickFileAsync(); console.log(file.textSync()); } catch (error) { console.error(error); }
Downloading files
Using downloadFileAsync:
import { Directory, File, Paths } from 'expo-file-system'; const url = 'https://pdfobject.com/pdf/sample.pdf'; const destination = new Directory(Paths.cache, 'pdfs'); try { destination.create(); const output = await File.downloadFileAsync(url, destination); console.log(output.exists); // true console.log(output.uri); // path to the downloaded file, e.g., '${cacheDirectory}/pdfs/sample.pdf' } catch (error) { console.error(error); }
Or using expo/fetch:
import { fetch } from 'expo/fetch'; import { File, Paths } from 'expo-file-system'; const url = 'https://pdfobject.com/pdf/sample.pdf'; const response = await fetch(url); const src = new File(Paths.cache, 'file.pdf'); src.write(await response.bytes());
Uploading files using expo/fetch
You can upload files as blobs directly with fetch built into the Expo package:
import { fetch } from 'expo/fetch'; import { File, Paths } from 'expo-file-system'; const file = new File(Paths.cache, 'file.txt'); file.write('Hello, world!'); const response = await fetch('https://example.com', { method: 'POST', body: file, });
Or using the FormData constructor:
import { fetch } from 'expo/fetch'; import { File, Paths } from 'expo-file-system'; const file = new File(Paths.cache, 'file.txt'); file.write('Hello, world!'); const formData = new FormData(); formData.append('data', file); const response = await fetch('https://example.com', { method: 'POST', body: formData, });
Moving and copying files
import { Directory, File, Paths } from 'expo-file-system'; try { const file = new File(Paths.document, 'example.txt'); file.create(); console.log(file.uri); // '${documentDirectory}/example.txt' const copiedFile = new File(Paths.cache, 'example-copy.txt'); file.copy(copiedFile); console.log(copiedFile.uri); // '${cacheDirectory}/example-copy.txt' file.move(Paths.cache); console.log(file.uri); // '${cacheDirectory}/example.txt' file.move(new Directory(Paths.cache, 'newFolder')); console.log(file.uri); // '${cacheDirectory}/newFolder/example.txt' } catch (error) { console.error(error); }
Using legacy FileSystem API
import * as FileSystem from 'expo-file-system/legacy'; import { File, Paths } from 'expo-file-system'; try { const file = new File(Paths.cache, 'example.txt'); const content = await FileSystem.readAsStringAsync(file.uri); console.log(content); } catch (error) { console.error(error); }
Listing directory contents recursively
import { Directory, Paths } from 'expo-file-system'; function printDirectory(directory: Directory, indent: number = 0) { console.log(`${' '.repeat(indent)} + ${directory.name}`); const contents = directory.list(); for (const item of contents) { if (item instanceof Directory) { printDirectory(item, indent + 2); } else { console.log(`${' '.repeat(indent + 2)} - ${item.name} (${item.size} bytes)`); } } } try { printDirectory(new Directory(Paths.cache)); } catch (error) { console.error(error); }
API
Constants
Type: '100'
The default debounce time for file system watcher events in milliseconds.
Classes
Type: Class extends FileSystemDirectory
Represents a directory on the filesystem.
A Directory instance can be created for any path, and does not need to exist on the filesystem during creation.
The constructor accepts an array of strings that are joined to create the directory URI. The first argument can also be a Directory instance (like Paths.cache).
Example
const directory = new Directory(Paths.cache, "subdirName");
Directory Properties
unionA size of the directory in bytes. Null if the directory does not exist, or it cannot be read.
Acceptable values are: number | null
stringRepresents the directory URI. The field is read-only, but it may change as a result of calling some methods such as move.
Directory Methods
| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Copies a directory.
Promise<void>| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Copies a directory synchronously.
void| Parameter | Type |
|---|---|
| options(optional) | DirectoryCreateOptions |
Creates a directory that the current uri points to.
voidDeletes a directory. Also deletes all files and directories inside the directory.
voidRetrieves an object containing properties of a directory.
DirectoryInfoAn object with directory metadata (for example, size, creation date, and so on).
| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Moves a directory. Updates the uri property that now points to the new location.
Promise<void>| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Moves a directory synchronously. Updates the uri property that now points to the new location.
void| Parameter | Type | Description |
|---|---|---|
| callback | (event: WatchEvent<File | Directory>) => void | Invoked when a change is detected. Receives a |
| options(optional) | WatchOptions | Configuration for debouncing and filtering events. |
Watches this directory for changes to its contents or the directory itself.
Events are emitted when files or subdirectories are created, modified, deleted, or renamed
within this directory. On iOS, child changes are surfaced as a coarse-grained modified event
on the directory itself, so filtering for child-level created, deleted, or renamed events
is not reliable. The watcher automatically stops when the directory is deleted or renamed.
To stop watching manually, call remove() on the returned subscription.
WatchSubscriptionA subscription handle. Call remove() to stop watching.
Example
const cacheDir = new Directory(Paths.cache); const subscription = cacheDir.watch((event) => { console.log(`${event.type}: ${event.target.uri}`); }); // Later, stop watching: subscription.remove();
Type: Class extends FileSystemDownloadTask
Represents a download task with pause/resume support and progress tracking.
DownloadTask Properties
DownloadTask Methods
| Parameter | Type |
|---|---|
| eventName | EventName |
| listener | DownloadTaskEvents[EventName] |
Adds a listener for the given event name.
EventSubscription| Parameter | Type |
|---|---|
| eventName | EventName |
| ...args | Parameters<DownloadTaskEvents[EventName]> |
Synchronously calls all the listeners attached to that specific event. The event can include any number of arguments that will be passed to the listeners.
void| Parameter | Type |
|---|---|
| eventName | EventName |
Returns a number of listeners added to the given event.
numberPromise<void>A function that detaches the JS and native objects to let the native object deallocate before the JS object gets deallocated by the JS garbage collector. Any subsequent calls to native functions of the object will throw an error as it is no longer associated with its native counterpart.
In most cases, you should never need to use this function, except some specific performance-critical cases when
manual memory management makes sense and the native object is known to exclusively retain some native memory
(such as binary data or image bitmap). Before calling this function, you should ensure that nothing else will use
this object later on. Shared objects created by React hooks are usually automatically released in the effect's cleanup phase,
for example: useVideoPlayer() from expo-video and useImage() from expo-image.
void| Parameter | Type |
|---|---|
| eventName | 'progress' |
Removes all listeners for the given event name.
void| Parameter | Type |
|---|---|
| eventName | EventName |
| listener | DownloadTaskEvents[EventName] |
Removes a listener for the given event name.
voidPromise<string | null>DownloadPauseStatePromise<string | null>| Parameter | Type |
|---|---|
| eventName | EventName |
Function that is automatically invoked when the first listener for an event with the given name is added. Override it in a subclass to perform some additional setup once the event started being observed.
voidType: Class extends FileSystemFile implements Blob
Represents a file on the filesystem.
A File instance can be created for any path, and does not need to exist on the filesystem during creation.
The constructor accepts an array of strings that are joined to create the file URI. The first argument can also be a Directory instance (like Paths.cache) or a File instance (which creates a new reference to the same file).
Example
const file = new File(Paths.cache, "subdirName", "file.txt");
File Properties
unionA creation time of the file expressed in milliseconds since the epoch. Returns a null if the file does not exist, cannot be read or the Android version is earlier than API 26.
Acceptable values are: number | null
booleanA boolean representing if a file exists. true if the file exists, false otherwise.
Also, false if the application does not have read access to the file.
unionA last modification time of the file expressed in milliseconds since the epoch. Returns a null if the file does not exist, or if it cannot be read.
Acceptable values are: number | null
unionA md5 hash of the file. Null if the file does not exist, or it cannot be read.
Acceptable values are: string | null
Deprecated: In favor of
lastModifiedto be more in line with webFile
unionA last modification time of the file expressed in milliseconds since the epoch. Returns a null if the file does not exist, or if it cannot be read.
Acceptable values are: number | null
numberA size of the file in bytes. 0 if the file does not exist, or it cannot be read.
stringA mime type of the file. An empty string if the file does not exist, or it cannot be read.
File Methods
The arrayBuffer() method of the Blob interface returns a Promise that resolves with the contents of the blob as binary data contained in an ArrayBuffer.
Promise<ArrayBuffer>Retrieves content of the file as base64.
Promise<string>A promise that resolves with the contents of the file as a base64 string.
Retrieves content of the file as base64.
stringThe contents of the file as a base64 string.
Retrieves byte content of the entire file.
Promise<Uint8Array<ArrayBuffer>>A promise that resolves with the contents of the file as a Uint8Array.
Retrieves byte content of the entire file.
Uint8ArrayThe contents of the file as a Uint8Array.
| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Copies a file.
Promise<void>| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Copies a file synchronously.
void| Parameter | Type | Description |
|---|---|---|
| url | string | The URL of the file to download. |
| destination | File | Directory | The destination directory or file. |
| options(optional) | DownloadTaskOptions | Download options including headers, progress callback, and abort signal. |
Creates a download task for downloading a file with pause/resume support.
DownloadTaskA DownloadTask instance that can be used to control the download.
Example
const dest = new File(Paths.document, 'video.mp4'); const downloadTask = File.createDownloadTask(url, dest, { onProgress: ({ bytesWritten, totalBytes }) => { console.log(`Downloaded ${bytesWritten} of ${totalBytes} bytes`); } }); const file = await downloadTask.downloadAsync();
| Parameter | Type | Description |
|---|---|---|
| url | string | The URL to upload the file to. |
| options(optional) | UploadOptions | Upload options including upload type, headers, progress callback, and abort signal. |
Creates an upload task for uploading this file with progress tracking.
UploadTaskAn UploadTask instance that can be used to control the upload.
Example
const file = new File(Paths.document, 'photo.jpg'); const uploadTask = file.createUploadTask(url, { uploadType: UploadType.MULTIPART, headers: { Authorization: 'Bearer token' }, onProgress: ({ bytesSent, totalBytes }) => { console.log(`Uploaded ${bytesSent} of ${totalBytes} bytes`); } }); const result = await uploadTask.uploadAsync(); console.log('Upload status:', result.status);
| Parameter | Type |
|---|---|
| options(optional) | InfoOptions |
Retrieves an object containing properties of a file
FileInfoAn object with file metadata (for example, size, creation date, and so on).
| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Moves a directory. Updates the uri property that now points to the new location.
Promise<void>| Parameter | Type |
|---|---|
| destination | File | Directory |
| options(optional) | RelocationOptions |
Moves a file synchronously. Updates the uri property that now points to the new location.
void| Parameter | Type | Description |
|---|---|---|
| mode(optional) | FileMode | The
|
Returns A FileHandle object that can be used to read and write data to the file.
FileHandle| Parameter | Type | Description |
|---|---|---|
| options(optional) | PickSingleFileOptions | options |
An overload of the pickFileAsync method, which picks and returns a single File.
This overload requires options to have multipleFiles flag be undefined or false.
Promise<PickSingleFileResult>| Parameter | Type | Description |
|---|---|---|
| options(optional) | PickMultipleFilesOptions | options |
An overload of the pickFileAsync method, which picks and returns a list of File's.
This overload requires options to have multipleFiles flag be true.
Promise<PickMultipleFilesResult>Deprecated: Use
pickFileAsync({initialUri, mimeTypes: mimeType})instead.
| Parameter | Type | Description |
|---|---|---|
| initialUri(optional) | string | An optional URI pointing to an initial folder on which the file picker is opened. |
| mimeType(optional) | string | A mime type that is used to filter out files that can be picked out. |
ReadableStream<Uint8Array<ArrayBuffer>>| Parameter | Type |
|---|---|
| start(optional) | number |
| end(optional) | number |
| contentType(optional) | string |
The slice() method of the Blob interface creates and returns a new Blob object which contains data from a subset of the blob on which it's called.
BlobThe stream() method of the Blob interface returns a ReadableStream which upon reading returns the data contained within the Blob.
ReadableStream<Uint8Array<ArrayBuffer>>Retrieves text from the file.
Promise<string>A promise that resolves with the contents of the file as string.
Retrieves text from the file.
stringThe contents of the file as string.
| Parameter | Type | Description |
|---|---|---|
| url | string | The URL to upload the file to. |
| options(optional) | UploadOptions | Upload options. |
Uploads this file to the network.
The promise resolves with the HTTP response metadata and body for any completed response, including non-2xx status codes. It rejects only for local file errors, transport failures, or cancellation.
Promise<UploadResult>| Parameter | Type | Description |
|---|---|---|
| callback | (event: WatchEvent<File>) => void | Invoked when a change is detected. Receives a |
| options(optional) | WatchOptions | Configuration for debouncing and filtering events. |
Watches this file for changes on the filesystem.
The watcher automatically stops when the file is deleted or renamed. To stop watching manually,
call remove() on the returned subscription.
WatchSubscriptionA subscription handle. Call remove() to stop watching.
Example
const file = new File(Paths.cache, 'data.json'); const subscription = file.watch((event) => { console.log(`File ${event.type}`); }); // Later, stop watching: subscription.remove();
WritableStream<Uint8Array<ArrayBufferLike>>| Parameter | Type | Description |
|---|---|---|
| content | string | Uint8Array<ArrayBufferLike> | The content to write into the file. |
| options(optional) | FileWriteOptions | - |
Writes content to the file.
voidType: Class extends PathUtilities
Paths Properties
Record<string, Directory>numberA property that represents the available space on device's internal storage, represented in bytes.
DirectoryA property containing the bundle directory – the directory where assets bundled with the application are stored.
DirectoryA property containing the cache directory – a place to store files that can be deleted by the system when the device runs low on storage.
DirectoryA property containing the document directory – a place to store files that are safe from being deleted by the system.
Paths Methods
| Parameter | Type | Description |
|---|---|---|
| path | string | File | Directory | The path to get the base name from. |
| ext(optional) | string | An optional file extension. |
Returns the base name of a path.
stringA string representing the base name.
Returns the directory name of a path.
stringA string representing the directory name.
Returns the extension of a path.
stringA string representing the extension.
| Parameter | Type |
|---|---|
| ...uris | string[] |
Returns an object that indicates if the specified path represents a directory.
PathInfoChecks if a path is absolute.
booleantrue if the path is absolute, false otherwise.
Joins path segments into a single path.
stringA string representing the joined path.
Normalizes a path.
stringA string representing the normalized path.
Parses a path into its components.
{
base: string,
dir: string,
ext: string,
name: string,
root: string
}An object containing the parsed path components.
Type: Class extends FileSystemUploadTask
Represents an upload task with progress tracking and cancellation support.
UploadTask Properties
UploadTaskStateUploadTask Methods
| Parameter | Type |
|---|---|
| eventName | EventName |
| listener | UploadTaskEvents[EventName] |
Adds a listener for the given event name.
EventSubscription| Parameter | Type |
|---|---|
| eventName | EventName |
| ...args | Parameters<UploadTaskEvents[EventName]> |
Synchronously calls all the listeners attached to that specific event. The event can include any number of arguments that will be passed to the listeners.
void| Parameter | Type |
|---|---|
| eventName | EventName |
Returns a number of listeners added to the given event.
numberA function that detaches the JS and native objects to let the native object deallocate before the JS object gets deallocated by the JS garbage collector. Any subsequent calls to native functions of the object will throw an error as it is no longer associated with its native counterpart.
In most cases, you should never need to use this function, except some specific performance-critical cases when
manual memory management makes sense and the native object is known to exclusively retain some native memory
(such as binary data or image bitmap). Before calling this function, you should ensure that nothing else will use
this object later on. Shared objects created by React hooks are usually automatically released in the effect's cleanup phase,
for example: useVideoPlayer() from expo-video and useImage() from expo-image.
void| Parameter | Type |
|---|---|
| eventName | 'progress' |
Removes all listeners for the given event name.
void| Parameter | Type |
|---|---|
| eventName | EventName |
| listener | UploadTaskEvents[EventName] |
Removes a listener for the given event name.
void| Parameter | Type |
|---|---|
| eventName | EventName |
Function that is automatically invoked when the first listener for an event with the given name is added. Override it in a subclass to perform some additional setup once the event started being observed.
void| Parameter | Type |
|---|---|
| eventName | EventName |
Function that is automatically invoked when the last listener for an event with the given name is removed. Override it in a subclass to perform some additional cleanup once the event is no longer observed.
voidPromise<UploadResult>FileHandle Properties
unionA property that indicates the current byte offset in the file. Calling readBytes or writeBytes will read or write a specified amount of bytes starting from this offset. The offset is incremented by the number of bytes read or written.
The offset can be set to any value within the file size. If the offset is set to a value greater than the file size, the next write operation will append data to the end of the file.
Null if the file handle is closed.
Acceptable values are: number | null
FileHandle Methods
Closes the file handle. This allows the file to be deleted, moved or read by a different process. Subsequent calls to readBytes or writeBytes will throw an error.
void| Parameter | Type | Description |
|---|---|---|
| length | number | The number of bytes to read. |
Reads the specified amount of bytes from the file at the current offset. Max amount of bytes read at once is capped by ArrayBuffer max size (32 bit signed MAX_INT on Android and 64 bit on iOS), but you can read from a FileHandle multiple times.
Uint8Array<ArrayBuffer>| Parameter | Type | Description |
|---|---|---|
| bytes | Uint8Array | A |
Writes the specified bytes to the file at the current offset.
voidMethods
Deprecated: Use
new File().copy()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| options | RelocatingOptions |
Promise<void>Deprecated: Import this method from
expo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| uri | string |
| fileUri | string |
| options(optional) | DownloadOptions |
| callback(optional) | FileSystemNetworkTaskProgressCallback<DownloadProgressData> |
| resumeData(optional) | string |
anyDeprecated: Import this method from
expo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| url | string |
| fileUri | string |
| options(optional) | FileSystemUploadOptions |
| callback(optional) | FileSystemNetworkTaskProgressCallback<UploadProgressData> |
anyDeprecated: Use
new File().delete()ornew Directory().delete()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
| options(optional) | DeletingOptions |
Promise<void>Deprecated: Use
File.downloadFileAsyncor import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| uri | string |
| fileUri | string |
| options(optional) | DownloadOptions |
Promise<FileSystemDownloadResult>Deprecated: Import this method from
expo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
Promise<string>Deprecated: Use
Paths.availableDiskSpaceor import this method fromexpo-file-system/legacy. This method will throw in runtime.
Promise<number>Deprecated: Use
new File().infoor import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
| options(optional) | InfoOptions |
Deprecated: Use
Paths.totalDiskSpaceor import this method fromexpo-file-system/legacy. This method will throw in runtime.
Promise<number>Deprecated: Use
new Directory().create()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
| options(optional) | MakeDirectoryOptions |
Promise<void>Deprecated: Use
new File().move()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| options | RelocatingOptions |
Promise<void>Deprecated: Use
new File().text()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
| options(optional) | ReadingOptions |
Promise<string>Deprecated: Use
new Directory().list()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
Promise<string[]>Deprecated: Use
@expo/fetchor import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| url | string |
| fileUri | string |
| options(optional) | FileSystemUploadOptions |
Promise<FileSystemUploadResult>Deprecated: Use
new File().write()or import this method fromexpo-file-system/legacy. This method will throw in runtime.
| Parameter | Type |
|---|---|
| fileUri | string |
| contents | string |
| options(optional) | WritingOptions |
Promise<void>Types
| Property | Type | Description |
|---|---|---|
| idempotent(optional) | boolean | This flag controls whether the If Default: false |
| intermediates(optional) | boolean | Whether to create intermediate directories if they do not exist. Default: false |
| overwrite(optional) | boolean | Whether to overwrite the directory if it exists. Default: false |
| Property | Type | Description |
|---|---|---|
| creationTime(optional) | number | A creation time of the directory expressed in milliseconds since epoch. Returns null if the Android version is earlier than API 26. |
| exists | boolean | Indicates whether the directory exists. |
| files(optional) | string[] | A list of file names contained within a directory. |
| modificationTime(optional) | number | The last modification time of the directory expressed in milliseconds since epoch. |
| size(optional) | number | The size of the file in bytes. |
| uri(optional) | string | A |
| Property | Type | Description |
|---|---|---|
| headers(optional) | undefined | The headers to send with the request. |
| idempotent(optional) | boolean | This flag controls whether the If Default: false |
| onProgress(optional) | (data: DownloadProgress) => void | A callback that is invoked with progress updates during the download. |
| signal(optional) | AbortSignal | An |
Represents the state of a paused download that can be persisted and resumed later.
| Property | Type | Description |
|---|---|---|
| fileUri | string | The destination file or directory URI. |
| headers(optional) | Record<string, string> | Custom headers that were used for the download request. |
| isDirectory | boolean | Whether the destination is a directory. When |
| resumeData(optional) | string | Platform-specific opaque resume data. |
| url | string | The URL of the download. |
Data provided to the onProgress callback during a file download.
| Property | Type | Description |
|---|---|---|
| bytesWritten | number | The number of bytes written so far. |
| totalBytes | number | The total number of bytes expected to be downloaded. |
Options for download task operations.
| Property | Type | Description |
|---|---|---|
| headers(optional) | Record<string, string> | Custom headers to include in the request. |
| onProgress(optional) | (data: DownloadProgress) => void | Callback for download progress updates. |
| sessionType(optional) | NetworkTaskSessionType | Only for: iOS Determines whether the iOS native session should continue in the background. Android accepts this option for API consistency and ignores it. When set to Default: 'background' |
| signal(optional) | AbortSignal | AbortSignal to cancel the download. |
Literal Type: string
Represents the current state of a download task.
Acceptable values are: 'idle' | 'active' | 'paused' | 'completed' | 'cancelled' | 'error'
| Property | Type | Description |
|---|---|---|
| intermediates(optional) | boolean | Whether to create intermediate directories if they do not exist. Default: false |
| overwrite(optional) | boolean | Whether to overwrite the file if it exists. Default: false |
| Property | Type | Description |
|---|---|---|
| creationTime(optional) | number | A creation time of the file expressed in milliseconds since epoch. Returns null if the Android version is earlier than API 26. |
| exists | boolean | Indicates whether the file exists. |
| md5(optional) | string | Present if the |
| modificationTime(optional) | number | The last modification time of the file expressed in milliseconds since epoch. |
| size(optional) | number | The size of the file in bytes. |
| uri(optional) | string | A URI pointing to the file. This is the same as the |
| Property | Type | Description |
|---|---|---|
| append(optional) | boolean | Whether to append the contents to the end of the file or overwrite the existing file. Default: false |
| encoding(optional) | EncodingType | 'utf8' | 'base64' | The encoding format to use when writing the file. Default: FileSystem.EncodingType.UTF8 |
| Property | Type | Description |
|---|---|---|
| md5(optional) | boolean | Whether to return the MD5 hash of the file. Default: false |
Literal Type: string
The native URL session mode used by iOS upload and download tasks.
Acceptable values are: 'background' | 'foreground'
| Property | Type | Description |
|---|---|---|
| exists | boolean | Indicates whether the path exists. Returns true if it exists; false if the path does not exist or if there is no read permission. |
| isDirectory | boolean | null | Indicates whether the path is a directory. Returns true or false if the path exists; otherwise, returns null. |
Result type for a canceled file pick.
| Property | Type | Description |
|---|---|---|
| canceled | true | - |
| result | null | - |
| Property | Type | Description |
|---|---|---|
| initialUri(optional) | string | A URI pointing to an initial folder in which the file picker is opened. |
| mimeTypes(optional) | string | string[] | The MIME type(s) of the documents that are available
to be picked. It also supports wildcards like Default: '*/*' |
| multipleFiles(optional) | boolean | Allows multiple files to be selected from the system UI. Default: false |
Options for picking multiple files.
Type: PickFileGeneralOptions extended by:
| Property | Type | Description |
|---|---|---|
| multipleFiles | true | - |
Literal Type: union
Result type for picking multiple files.
Acceptable values are: PickMultipleFilesSuccessResult | PickFileCanceledResult
Result type for a successful picking multiple files.
| Property | Type | Description |
|---|---|---|
| canceled | false | - |
| result | File[] | - |
Options for picking a single file.
Type: PickFileGeneralOptions extended by:
| Property | Type | Description |
|---|---|---|
| multipleFiles(optional) | false | - |
Literal Type: union
Result type for picking a single file.
Acceptable values are: PickSingleFileSuccessResult | PickFileCanceledResult
Result type for successfully picking a single file.
| Property | Type | Description |
|---|---|---|
| canceled | false | - |
| result | File | - |
Options for upload operations.
| Property | Type | Description |
|---|---|---|
| fieldName(optional) | string | The field name for the file in multipart uploads. Default: 'file' |
| headers(optional) | Record<string, string> | Custom headers to include in the request. |
| httpMethod(optional) | 'POST' | 'PUT' | 'PATCH' | The HTTP method to use. Default: 'POST' |
| mimeType(optional) | string | The MIME type of the file. |
| onProgress(optional) | (data: UploadProgress) => void | Callback for upload progress updates.
|
| parameters(optional) | Record<string, string> | Additional form parameters to include in multipart uploads. |
| sessionType(optional) | NetworkTaskSessionType | Only for: iOS Determines whether the iOS native session should continue in the background. When set to Default: 'background' |
| signal(optional) | AbortSignal | An |
| uploadType(optional) | UploadType | The type of upload operation. Default: UploadType.BINARY_CONTENT |
Represents upload progress data.
| Property | Type | Description |
|---|---|---|
| bytesSent | number | The number of bytes sent so far. |
| totalBytes | number | The total number of bytes to send. |
Represents the result of an upload operation.
| Property | Type | Description |
|---|---|---|
| body | string | The response body as a string. |
| headers | Record<string, string> | The response headers. |
| status | number | The HTTP status code. |
Type: Exclude<'idle' | 'active' | 'paused' | 'completed' | 'cancelled' | 'error', 'paused'>
Represents the current state of an upload task.
Describes a change detected by a file system watcher.
| Property | Type | Description |
|---|---|---|
| nativeEventFlags(optional) | number | Raw platform-specific event flags for advanced use cases. On Android: FileObserver event flags. On iOS: DispatchSource.FileSystemEvent flags. |
| newTarget(optional) | T | Only for: Android For rename events, the new path after rename. Populated when MOVED_FROM and MOVED_TO events are correlated within the debounce window. |
| target | T | The file or directory that changed. For |
| type | WatchEventType | The kind of change that occurred. |
Literal Type: string
The type of change that triggered a watcher event.
created— a new file or directory was createdmodified— the file contents or metadata changeddeleted— the file or directory was removedrenamed— the file or directory was renamed or moved
Acceptable values are: 'created' | 'modified' | 'deleted' | 'renamed'
Options for configuring a file system watcher.
| Property | Type | Description |
|---|---|---|
| debounce(optional) | number | The debounce interval in milliseconds for coalescing rapid successive events into a single callback. Default: DEFAULT_DEBOUNCE_MS |
| events(optional) | WatchEventType[] | Limits which event types trigger the callback. If omitted, all event types are observed. On iOS, directory watchers only provide coarse-grained notifications that the directory itself
changed, so filtering for child-level |
A handle to an active file system watcher. Call remove() to stop watching and release resources.
| Property | Type | Description |
|---|---|---|
| remove | () => void | Stops watching for changes and releases native resources. After calling this method, the callback will no longer be invoked. |
Enums
Specifies the access mode when opening a file handle.
FileMode.ReadOnly = "r"Opens the file for reading only. The cursor is positioned at the beginning of the file.
FileMode.ReadWrite = "rw"Opens the file for both reading and writing. The cursor is positioned at the beginning of the file.
Note: This mode cannot be used with SAF (Storage Access Framework)
content://URIs.
FileMode.WriteOnly = "w"Opens the file for writing only. The cursor is positioned at the beginning of the file.
FileMode.Append = "wa"Opens the file for writing only. The cursor is positioned at the end of the file.
Note: For SAF files, this is a strict append-only mode. The cursor cannot be moved; calling
seek()will have no effect.