@napacitor/filesystem
Filesystem plugin: query app directories, read and copy bundled files, and open the system file picker. Wraps the .NET MAUI FileSystem and FilePicker APIs.
Installation
To use npm:
npm install @napacitor/filesystem
To use yarn:
yarn add @napacitor/filesystem
Sync native files:
npx nap sync
Usage
import { Filesystem } from '@napacitor/filesystem';
// ── Directory paths (FileSystem helpers) ────────────────────
const { cacheDirectory, dataDirectory } = await Filesystem.getDirectoryPaths();
console.log(cacheDirectory, dataDirectory);
// ── Bundled files (relative paths under Resources/Raw) ───────
const { data } = await Filesystem.readBundleFile({ path: 'config/settings.json' });
console.log(data); // file text content
// Copy a bundled file to the data directory (copies to the cache directory by default)
const { path } = await Filesystem.copyBundleFile({
path: 'docs/sample.pdf',
targetDirectory: 'data',
});
console.log(path);
// ── System file picker (FilePicker) ──────────────────────────
// Pick a single file (returns null when the user cancels)
const file = await Filesystem.pickFile({ types: 'images' });
if (file) {
console.log(file.name, file.size, file.path);
// file.data is base64 content, ready to upload / preview
}
// Pick multiple files (returns [] when the user cancels)
const files = await Filesystem.pickFiles({ title: 'Choose attachments', types: 'any' });
for (const f of files) {
console.log(f.name, f.size);
}
How It Works
Wraps the .NET MAUI FileSystem.Current and FilePicker.Default facades: getDirectoryPaths() returns CacheDirectory / AppDataDirectory; readBundleFile() reads a bundled resource under Resources/Raw through OpenAppPackageFileAsync and returns it as UTF-8 text; copyBundleFile() copies a bundled resource stream into the cache/data directory (packaged resources cannot be accessed directly as file paths, they must be materialized by copying the stream). pickFile() / pickFiles() call PickAsync / PickMultipleAsync on the UI thread (required by MAUI), then read each FileResult stream into memory and return it as base64 to JS; FullPath is only included when the platform provides it (not guaranteed to be a physical path).
Permissions
Android
No additional configuration required (the file picker goes through the system Storage Access Framework and the FileResult content is readable via system URI grants). Reading arbitrary local paths is out of scope for this plugin.
iOS
No additional configuration required.
Windows
No additional configuration required. PickOptions.PickerTitle is not shown on Windows.
API
getDirectoryPaths()
Gets the paths of the cache directory and the app data directory.
Returns: Promise<DirectoryPaths>
readBundleFile(options)
Reads the text content of a bundled file inside the app package (UTF-8; throws INVALID_ARGUMENTS when the resource does not exist).
| Param | Type |
|---|---|
options | ReadBundleFileOptions |
Returns: Promise<BundleFileResult>
copyBundleFile(options)
Copies a bundled file inside the app package to the cache directory or the data directory (throws INVALID_ARGUMENTS when the resource does not exist).
| Param | Type |
|---|---|
options | CopyBundleFileOptions |
Returns: Promise<CopyBundleFileResult>
pickFile(options?)
Opens the system file picker to select a single file; returns null when the user cancels.
| Param | Type |
|---|---|
options | PickFileOptions |
Returns: Promise<PickedFile | null>
pickFiles(options?)
Opens the system file picker to select multiple files; returns [] when the user cancels.
| Param | Type |
|---|---|
options | PickFileOptions |
Returns: Promise<PickedFile[]>
Interfaces
DirectoryPaths
| Prop | Type | Description |
|---|---|---|
cacheDirectory | string | The cache directory (may be cleared by the system; don't store critical data there). |
dataDirectory | string | The app data directory (synced with system backups). |
ReadBundleFileOptions
| Prop | Type | Description |
|---|---|---|
path | string | Resource path inside the app package (under MAUI Resources/Raw, e.g. 'config/settings.json'). |
BundleFileResult
| Prop | Type | Description |
|---|---|---|
data | string | File text content (UTF-8). |
CopyBundleFileOptions
| Prop | Type | Description |
|---|---|---|
path | string | Resource path inside the app package (under Resources/Raw). |
targetDirectory | 'cache' | 'data' | Target directory (defaults to 'cache'). |
fileName | string | Target file name (defaults to the source file name). |
CopyBundleFileResult
| Prop | Type | Description |
|---|---|---|
path | string | Absolute path of the copied file. |
PickFileOptions
| Prop | Type | Description |
|---|---|---|
title | string | Picker title (not shown on Windows). |
types | 'any' | 'images' | 'videos' | File type filter (defaults to 'any', no filter). |
PickedFile
| Prop | Type | Description |
|---|---|---|
name | string | File name. |
path | string | Physical path when available from the platform (don't rely on it; use data for the content). |
size | number | File size in bytes. |
data | string | File content encoded as base64. |