react-native-fs provides comprehensive native filesystem access for React Native applications across iOS, Android, and Windows platforms. It offers a robust API for common file operations such as reading, writing, and deleting files, managing directories, and facilitating advanced use cases like background file downloads and uploads with progress tracking. The library is actively maintained, with the current stable version being 2.20.0, and receives regular updates to address compatibility with new React Native versions and underlying OS changes, exemplified by recent fixes for iOS crashes and Android type corrections. A key differentiator is its direct native integration, enabling features like handling content URIs on Android and asset video URIs on iOS, which are crucial for complex media and document management within mobile applications. It carefully manages compatibility across various React Native versions, requiring specific `react-native-fs` versions depending on the host `react-native` and Gradle versions, highlighting its sensitivity to the broader ecosystem.
npm install react-native-fsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic file operations: writing a string to a temporary file, reading its content, checking its existence, retrieving its statistics, and finally deleting it. It uses `RNFS.TemporaryDirectoryPath` for cross-platform compatibility.
For RN < 0.57, install `@2.11.17`. For RN >= 0.57 and Gradle >= 3, install `>= @2.13.2`. For RN >= 0.61, install `>= @2.16.0`.
Upgrade to `react-native-fs` version `2.14.0` or higher to gain AndroidX support. Ensure your Android project is fully migrated to AndroidX.
Update any code that relies on the `size` property to expect a `Double` instead of an `Int`.
Be aware of Android's scoped storage and file access limitations. For external storage, consider using methods like `ExternalStorageDirectoryPath` or `DownloadDirectoryPath` and ensure appropriate permissions (`READ_EXTERNAL_STORAGE`, `WRITE_EXTERNAL_STORAGE`) are declared and requested at runtime.
Follow the 'Background Downloads Tutorial (iOS)' in the official documentation carefully. Ensure `Manually flush & invalidate session upon completion` (as fixed in v2.17.0) is considered when managing download tasks.
Upgrade to `react-native-fs` version `2.19.0` or higher to resolve `NativeEventEmitter` warnings.
Upgrade `react-native-fs` to version `2.19.0` or newer: `npm install react-native-fs@latest` or `yarn add react-native-fs@latest`.
Upgrade `react-native-fs` to version `2.15.1` or higher, which includes a fix for this issue by importing `RCTImageLoaderProtocol`.
Ensure the library is properly linked (using `react-native link react-native-fs` or manual linking as per documentation). Verify the import statement is `import RNFS from 'react-native-fs';`.
Verify that your `react-native-fs` version supports your AndroidX migration status (v2.14.0+ for AndroidX). Check your `android/app/build.gradle` and `android/settings.gradle` for correct `react-native-fs` package inclusion, especially if using manual linking.