Read a File with the fs Plugin
Installing a plugin exposes none of its commands to the webview: each one
must be allowed by a capability first, and a missing permission fails at
runtime, not at compile time. In this lab we’ll take the create-tauri-app
vanilla TypeScript scaffold, add the file system plugin,
and grant it the one permission needed to read a file from the app’s data
directory. We’ll use pnpm, but any package manager works if you replace it
in the commands.
Verify the Scaffold
Section titled “Verify the Scaffold”Before changing anything, confirm the scaffold’s IPC works. Run the app and greet yourself from the input field:
pnpm tauri devThe greet command answering means the frontend, the IPC layer, and the
Rust backend are all wired up, so anything that breaks from here on was
caused by one of our changes.
Add the fs Plugin
Section titled “Add the fs Plugin”The plugins maintained by the Tauri team are listed in the
Plugins section. On the Rust side, adding one comes down to two
changes: the crate dependency in src-tauri/Cargo.toml and the plugin
registration on the builder in src-tauri/src/lib.rs. In this lab the
builder chain lives in a configure function that run calls, which is also
what the lab’s checks build the app from.
[dependencies]tauri = { version = "2", features = [] }tauri-plugin-opener = "2"tauri-plugin-fs = "2"serde = { version = "1", features = ["derive"] }serde_json = "1"pub fn configure<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Builder<R> { builder .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_fs::init()) .invoke_handler(tauri::generate_handler![greet])}The frontend needs the matching JavaScript bindings:
pnpm add @tauri-apps/plugin-fsGrant the Permission
Section titled “Grant the Permission”The plugin is registered, but its commands are still unreachable. Try reading a file from the app’s data directory:
import { readTextFile, BaseDirectory } from '@tauri-apps/plugin-fs';
const contents = await readTextFile('data.json', { baseDir: BaseDirectory.AppData,});The call rejects, and the error names the permissions that would allow it:
fs.read_text_file not allowed. Permissions associated with this command: fs:allow-read-text-file, ...The capability attached to the main window lives in
src-tauri/capabilities/default.json. Add the plugin’s
default permission set along with
read access to the app’s data directory:
"windows": ["main"], "permissions": [ "core:default", "opener:default" "opener:default", "fs:default", "fs:allow-appdata-read-recursive" ]}The same call now resolves with the file contents. Note how narrow the
grant is: it covers reads inside the app’s data directory and nothing else,
so reading from $HOME or writing anywhere still fails until a capability
allows it. Granting each scope on purpose is the point of the system.
Learn how to inspect and tailor what a plugin exposes in Using Plugin Permissions, and see the file system plugin reference for every permission and scope it ships.
© 2026 Tauri Contributors. CC-BY / MIT